當前位置:成語大全網 - 新華字典 - 用二維字符數組的每行儲存鍵盤輸入的字符串,將這些字符串按字典順序升序排列,按排列後的順序輸出!

用二維字符數組的每行儲存鍵盤輸入的字符串,將這些字符串按字典順序升序排列,按排列後的順序輸出!

1234

3456

7890

wwwwww

uuuuu

1234

3456

7890

uuuuu

wwwwww

Press any key to continue

#include <stdio.h>

#include <string.h>

#include <memory.h>

main()

{

int i,j;

char tmp[20]="\0",str[5][20];

memset(str,'\0',sizeof(str));

for (i=0;i<5;i++)

{

scanf("%s",str[i]);

}

for (i=0;i<5-1;i++)

{

for (j=0;j<5-i-1;j++)

{

if (strcmp(str[j],str[j+1])>0)

{

strcpy(tmp,str[j]);

strcpy(str[j],str[j+1]);

strcpy(str[j+1],tmp);

}

}

}

for (i=0;i<5;i++)

{

printf("%s\n",str[i]);

}

}