sorting an array of strings
i'm trying to sort an array of strings which I have declared globally. Each string is a number following by a word (e.g. 14 socks). I'm just interested in sorting by number as of now.
I've tried two different sorting techniques, and both compile and run but nothing gets sorted. Here's my code for one technique (the other technique is a selection sort):
Code:
char global[500][15];
char buff1[128]; //local
Code:
for (i=0;i<place;i++)
for (j=0;j<place;j++) //place is the number of elements in the array of strings
{
if(strcmp(global[i], global[j]) > 0) {
strcpy(buff1, &global[i][12]);
strcpy(&global[i][12], &global[j][12]);
strcpy(&global[j][12], buff1);
}
}
Is there something I'm missing?
I also know I can use qsort, but since I'm unfamiliar with that I'd prefer something that involves using a swap, like what I have above.