C语言求救!!输入一行字符,从中读出所有单词,并将所有单词的首字符组成字符串后输出。设单词以空格分隔

2024-12-20 12:46:48
推荐回答(2个)
回答1:

//快采纳给分吧
Enter the string
who is your daddy?
The new string is:wiyd
Press any key to continue

#include
#include
main()
{
char str[81],s[20],c;
int i,j,word=0;
printf("Enter the string\n"); gets(str);
i=0;j=0;
while((c=str[i])!='\0')
{
if(c==' ') /*空格表示单词结束*/
word=0;
else if(c!=' '&& word==0)
{
word=1;
s[j++]=c;
}
i++;
}
s[j]='\0';
printf("The new string is:%s\n",s);
}

回答2:

只要输出单词首字符组成的字符串,还是每个单词也要输出来?