Sorting numerical array error

Can anyone explain why this wont run? I'm getting the cant convert int* to const char error but i do not know why?

I'm trying to create a program that creates an array of 100 ints between 0 and 250 and then sorts them using a separate function, I've gotten this far

#include <iostream>
#include <stdlib.h>
#include <time.h>
#include <stdio.h>
#include <cstring>

using namespace std;

void quicksort (int *items, int len);
void qs (int *items, int left, int right);

int main(void)
{
int array[100];
srand(time(0));
for(int i=0; i<250; i++) array[i]=rand()%251;


cout<<"Original order: "<<array<<"/n";

quicksort (array, strlen(array));

cout<<"sorted order: "<<array<<"\n";

return 0;
}
void quicksort (int *items, int len)
{
qs(items,0,len-1);

}

void qs(int *items,int left, int right)
{
int i, j;
int x, y;

i=left; j=right;
x=items[(left+right)/2];

do {
while((items[i]<x)&&(i < right)) i++;
while((x<items[j])&&(j > left))j--;
if(i <=j) {
y_items [i];
items[i]=items[j];
items[j]=y;
i++; j--;
}
} while (i<=j;)
if(left <j) qs(items, left,j);
if(i<right)qs(items,i,right);
}

Compiler does usually mention the line of offending code.

1
2
3
4
size_t strlen ( const char * str );

int array[7];
size_t x = strlen( array ); // Is this the line of error? 
quicksort (array, strlen(array));

this line apparently? Cheers for the reply
strlen() returrns the number of characters in a null-terminated array of chars. You want the length of an array of int's which is different. You could use sizeof(array), which returns the number of bytes in array, or (sizeof(array)/sizeof(array[0])) which returns the number of items in the array.

Which one you use depends on what the "len" argument of quickSort is.
Topic archived. No new replies allowed.