<span style="font-size:18px;">//目的:输入五个国家的名称按字母顺序排列输出。
#include <stdio.h>
int main()
{</span>
<span style="font-size:18px;"> //cs[5][20]为二维字符数组,可分为五个一维数组cs[0],cs[1],cs[2],cs[3],cs[4]
char st[20],cs[5][20];
int i,j,p;
printf("输入国家英文名称:\n");
for(i=0;i<5;i++)
{
gets(cs[i]);//gets函数输入五个国家名字符串
}
printf("\n");
//排序输出
for(i=0;i<5;i++)
{
p=i;
strcpy(st,cs[i]);
for(j=i+1;j<5;j++)
if(strcmp(cs[j],st)<0)
{
//若有比st小者则把该字符串拷贝到st中,
//并把其下标赋予p
p=j;
strcpy(st,cs[j]);
}
if(p!=i)
{
strcpy(st,cs[i]);
strcpy(cs[i],cs[p]);
strcpy(cs[p],st);
}
puts(cs[i]); //输出排序后的国家
}
printf("\n");
return 0;
}
</span>
<span style="font-size:18px;">
</span>
出现的error :error: stray '\241' in program
问题原因:中文空格引起的,不好发现
解决方法:因为代码比较少,可以直接重写,或者根据提示找到行数来去掉空格