Look my example, I'll sort strings with an index help.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ROW 5
#define SIZE 30
void swap(int idx[], int j);
void printf_string(const char sStrs[ROW][SIZE], int idx[]);
int main(void)
{
const char sStrs[ROW][SIZE] = {
"my fool string",
"another fool idiot string",
"blah, nothing",
"need to say more",
"in a year or twice",
};
int idx[ROW] = {0,1,2,3,4};
int i,j;
printf("Before sorting: ");
printf_string(sStrs, idx);
for(i=0; i<ROW; ++i) {
for(j=0; j<ROW - (i+1); ++j)
if(strcmp(sStrs[idx[j]], sStrs[idx[j+1]]) > 0)
swap(idx, j);
}
printf("\nAfter sorting: ");
printf_string(sStrs, idx);
system("PAUSE");
return 0;
}
void swap(int idx[], int j)
{
int tmp;
tmp = idx[j];
idx[j] = idx[j+1];
idx[j+1] = tmp;
}
void printf_string(const char sStrs[ROW][SIZE], int idx[])
{
int i;
for(i=0; i<ROW; ++i)
printf("sStrs[%d] = %s\n",i,sStrs[idx[i]]);
}