jacksonyoyo
November 26th, 2011, 12:24 AM
Hi everyone.
I have defined and INT array in C, and its malloc()-ed.
int* array= malloc(200* sizeof(int));Even though memory is allocated to the array, however, the array may not have 200 elements, the number of elements changes in each round of a loop.
this array needs to then be passed to a qsort() function which requires the number of elements in the array in order to work.
void qsort( void *buf, size_t num, size_t size, int (*compare)(const void *, const void *) );So my question is, how can I get the number of elements in the array?
I have searched online, and the closest thing that I have got so far is :
sizeof(array)/sizeof(int)this just gives me the size of array, which is not what i want.
Please help,
thanks for everything in advance.
PS: thank you for the people who helped me with my last post :)
I have defined and INT array in C, and its malloc()-ed.
int* array= malloc(200* sizeof(int));Even though memory is allocated to the array, however, the array may not have 200 elements, the number of elements changes in each round of a loop.
this array needs to then be passed to a qsort() function which requires the number of elements in the array in order to work.
void qsort( void *buf, size_t num, size_t size, int (*compare)(const void *, const void *) );So my question is, how can I get the number of elements in the array?
I have searched online, and the closest thing that I have got so far is :
sizeof(array)/sizeof(int)this just gives me the size of array, which is not what i want.
Please help,
thanks for everything in advance.
PS: thank you for the people who helped me with my last post :)