當前位置:成語大全網 - 漢語詞典 - C語言的英語單詞按字典順序排序時,結果是錯誤的。錯在哪裏?

C語言的英語單詞按字典順序排序時,結果是錯誤的。錯在哪裏?

#包含?& ltstdio.h & gt

#包含?& ltstdlib.h & gt

#包含?& ltstring.h & gt

int?main()?//主函數?

{

int?I,j,m,k;

char*?a[40];

夏爾?temp[10]= { " abcdefghi " };

srand(time(NULL));

for(j = 0;j & lt40;j++)

{

a[j]=(char *)malloc(sizeof(char)* 10);

m = 4+rand()%(10-4);

for(I = 0;我& ltm;i++)

{

temp[I]= ' a '+rand()% 26;

}

temp[I]= ' \ 0 ';

strcpy(a[j],temp);

printf("%s\n ",a[j]);

}

for(I = 0;我& lt39;i++)

{

for(j = I;j & lt40;j++)

{

if(strcmp(a[i],a[j])& gt;0)

{

strcpy(temp,a[I]);

strcpy(a[i],a[j]);

strcpy(a[j],temp);

}

}

}

Printf("這40個詞按字典排序的輸出是:\ n ");

for(I = 0;我& lt40;i++)

{

printf("%s\n ",a[I]);

}

}