C语言求救!!输入一行字符,从中读出所有单词,并将所有单词的首字符组成字符串后输出。设单词以空格分隔
输入一行字符,从中读出所有单词,并将所有单词的首字符组成字符串后输出。设单词以空格分隔)。(用数组)#include<stdio.h>#include<string.h>...
输入一行字符,从中读出所有单词,并将所有单词的首字符组成字符串后输出。设单词以空格分隔)。(用数组)
#include<stdio.h>
#include<string.h>
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==' ') /*空格表示单词结束*/
_______________;
else if(c!=' '&& word==0)
{ word=1; _______________=c;}
i++;
}
___________________;
printf("The new string is:%s\n",s);
} 展开
#include<stdio.h>
#include<string.h>
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==' ') /*空格表示单词结束*/
_______________;
else if(c!=' '&& word==0)
{ word=1; _______________=c;}
i++;
}
___________________;
printf("The new string is:%s\n",s);
} 展开
2个回答
展开全部
//快采纳给分吧
Enter the string
who is your daddy?
The new string is:wiyd
Press any key to continue
#include<stdio.h>
#include<string.h>
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);
}
Enter the string
who is your daddy?
The new string is:wiyd
Press any key to continue
#include<stdio.h>
#include<string.h>
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);
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询