I am doing a school project with arrays using C. At the moment I am trying to sort the array of string to alphabetical order. I just can't seem to successfully do this. Here is the simplified code that I have done so far:
void sort_string_array(char **table)
{
int i = 0;
while (table[i++] != NULL); // to get the length
qsort(table, i, sizeof(char *), strcmp); // sorting
}
Is this a completely wrong solution style, am I close, what is wrong :P ? Any help would be awesome!
EDIT:
void sort_string_array(char **table)
{
int i = 0;
while (table[i] != NULL) i++; // to get the length
qsort(table, i, sizeof(char *), strcmp); // sorting
}
After correcting that error it is still not fuctioning right. Using string {'one','two','three','four'} first value of this sort should be 'four' but it is 'two'}