Comfuse qsort function

qsort has this format:
void qsort ( void * base, size_t num, size_t size, compare)

and these are the description of the first 3 parameters, ignore compare for now.
base.......Pointer to the first element of the array to be sorted.
num........Number of elements in the array pointed by base. size
Size.......Size in bytes of each element in the array.
size_t is an unsigned integral type.

it is variable Size that confuses me.

let's say
if base[3] = {"jose", "hitchcock", "jonhQ"}

here Size is the size in byte of each element which are different from each other. jose is 4 bytes, hitchcock is 9 bytes and johnQ is 5 bytes.

How do you deal then with raged array what Size to I put?
The elements in an array is always the same size.
const char* base[3] = {"jose", "hitchcock", "jonhQ"};
If this is how base is defined it means that each element in the array is a pointer so the size of each element will be sizeof(const char*).

qsort is a C function. If you are using C++ you should probably be using std::sort instead.
Topic archived. No new replies allowed.