I am trying to sort an array of structures alphabetically. Can this be done?
if yes, how? I can only find sorts that organise numerically. Any help would be appreciated.
Blue Bob
I am trying to sort an array of structures alphabetically. Can this be done?
if yes, how? I can only find sorts that organise numerically. Any help would be appreciated.
Blue Bob
If you're sorting characters or strings thats the same as sorting numbers, since they get converted to their ascii equivalents.
Yes, just read the string in each struct's first character and compare. Simple as that...
1978 Silver Anniversary Corvette
Or ...
from string.hCode:int strcmp (const char *s1, const char *s2);
Doesn't that function just tell if the strings are the same or not? Returning only a 0 or 1. Please correct me if I'm wrong...
1978 Silver Anniversary Corvette
Check your system's documentation on the qsort() library function. I believe that is what you are after.
Jason Deckard
if s1 is less that s2, strcmp will return a negative number. if they are equal, zero is returned. if s1 is greater than s2 strcmp will return a positive number.Originally posted by Garfield
Doesn't that function just tell if the strings are the same or not? Returning only a 0 or 1. Please correct me if I'm wrong...