#include<stdio.h>
#include<string.h>
int main()
{
char ch[100][100];
char c;
char temp[100][100];
int i=0,j=0;
/*将整个句子中的单词分离出来*/
while((c=getchar())!='\n')
{
if(c!=' ')
{
ch[i][j]=c;
j++;
}
else
{
ch[i][j]='\0';
j=0;
i++;
}
}
ch[i][j]='\0';
/*按字典的顺序排列*/
for(int k=0;k<=i;k++)
{
for(int m=k+1;m<=i;m++)
{
if(strcmp(ch[k],ch[m])>0)
{
strcpy(temp[i],ch[k]);
strcpy(ch[k],ch[m]);
strcpy(ch[m],temp[i]);
}
}
}
/*输出排列后的单词*/
for(int k=0;k<=i;k++)
printf("%s\n",ch[k]);
}
关键是怎样放进去???
追答首先把句子读到一个字符串里,然后按刚才的方法从字符串中读
追问能麻烦你把这一段程序写出来吗?我基础比较差,还是不会!呜~~~
追答只能说C语言的学习是靠练习练出来的。。。你懂我的意思吧。
I am sorry,I do not understand !
追答Sorry, this is C Language. You can use to Yahoo slouch !