0
qsort(Names, numberOfFriends, 50, strcmp);

I tried to make an alphabetical sort on Names (wich is a double pointer). every string in the double pointer is dynamically allocated string, wich means every string have a different size. One of the parameters of the qsort function, is the size of the strings (it's actually a function that ment to 2d array, and not for double pointers with dynamically allocated strings).

How can i do an alphabetical sort on double pointers that have dynamically allocated strings?

  • Do you want to write a `qsort` function? – tom Apr 28 '18 at 12:41
  • Yes, it will be helpful to write the function , but every code that get the jobe done - is great. – user4978484 Apr 28 '18 at 12:44
  • See partial answer below ... and I suggest if you want help with the sort routine you should post what you have or want modified -- otherwise your question is 'please write me a piece of code to do what I need' - it is better to ask 'how to convert this code from 2D array to ** pointer type?' – tom Apr 28 '18 at 12:48
  • This is my first question in stack overflow - For next time. Thank you sir for your help. – user4978484 Apr 28 '18 at 12:51

1 Answers1

0

Partial answer

The number of characters in the string is not so important - see this question - strcmp will compare the first n bytes of the arrays where the first n-1 bytes are the same.

so to compare Names[i] and Names[j] you should be able to use

differentce=strcmp(Names[i], Names[j]);

provided that Names is declared as char ** Names.

If you want more help with how to do this I suggest you put more code in your question.

tom
  • 1,303
  • 10
  • 17