单词排序,输出时少了单词(并没有输出全部的单词,而是以空行的形式输出)
程序代码:
#include<stdio.h> #include <string.h> main() {char words[5][15]={{'\0'},{'\0'},{'\0'},{'\0'},{'\0'}},temp[15]={0}; int i,j; scanf("%s",words[0]); for (i=1;i<5;i++) { scanf("%s",temp); //strcpy(words[i],temp); j=i-1; while(strcmp(temp,words[j])>0) { strcpy(words[j+1],words[j]); j--; } strcpy(words[j+1],temp); } for (i=0;i<5;i++) printf("%s\n",words[i]); printf("\n"); }
[此贴子已经被作者于2016-11-12 23:25编辑过]