hi ...
i'm trying to sort an array of string.
my code should sort my array alphabetically [a-z] ,but it dos not do that ..
output :Code:int main(void) { char mov[7][25]; int f,c,i; ///first , current , i-->char index 0-24; int tmp,save[7]={0,1,2,3,4,5,6}; i=23; strcpy(mov[0],"Cheaper by the Dozen 2"); strcpy(mov[1],"Drumline"); strcpy(mov[2],"Ever After"); strcpy(mov[3],"Cheaper by the Dozen"); strcpy(mov[4],"Mr. & Mrs. Smith"); strcpy(mov[5],"X-Men"); strcpy(mov[6],"Toy Story 2"); puts("<----before---->"); for(i=0;i<7;i++)puts(mov[save[i]]); puts("<--------------->"); while(i>=0) { for(f=0;f<6;f++) for(c=f+1;c<7;c++) { if(mov[f][i]<mov[c][i]) { tmp=save[f]; save[f]=save[c]; save[c]=tmp; } } i--; } puts("<-----after----->"); for(i=0;i<7;i++)puts(mov[save[i]]); puts("<--------------->"); return 0; }
<----before---->
Cheaper by the Dozen 2
Drumline
Ever After
Cheaper by the Dozen
Mr. & Mrs. Smith
X-Men
Toy Story 2
<--------------->
<-----after----->
Cheaper by the Dozen 2
Drumline
Mr. & Mrs. Smith
Ever After
X-Men
Cheaper by the Dozen
Toy Story 2
<--------------->
as you see in the output the string is not sorted .. i think, I'm missing something basic here...



LinkBack URL
About LinkBacks


