Friday, 15 June 2012

c++ - segmentation fault using q sort? -



c++ - segmentation fault using q sort? -

i trying sort pointer array of characters using qsort , maintain getting segmentation fault when compile. post code qsort phone call , compare function , help appreciated.

//count declaration size_t count = (sizeof (strptrsqsort)/sizeof (*strptrsqsort)); //function phone call qsort ((char *)ptr, size, sizeof(char), compare); //compare function int compare (const void *a, const void *b) { const char **ia = (const char **)a; const char **ib = (const char **)b; homecoming strcmp (*ia, *ib); }

judging qsort call, sorting array of char elements: base of operations pointer type passed qsort char * value , element size sizeof(char). however, comparing function written array of pointers char. that's wrong , inconsistent. causing crash.

in accompanying text state "trying sort pointer array of characters". why in case specifying element size sizeof(char) , not as, say, sizeof (char *)?

c++ qsort

No comments:

Post a Comment