#includevoid main(){char string[81];int i,num=0;word=0;char c;gets(string[i];for(i=0;(c=string[i])!='\0';i++)if(c==' ') word=0;else if(word==0){word=1;num++;}printf("There are %d words in the line.\n",num)}

来源:学生作业帮助网 编辑:作业帮 时间:2024/11/26 02:01:44
#includevoid main(){char string[81];int i,num=0;word=0;char c;gets(string[i];for(i=0;(c=string[i])!='\0';i++)if(c==' ') word=0;else if(word==0){word=1;num++;}printf(
xSMo@+Tv *59PcJ CDiCUHB4v6B?]kRRփٙ XSr+iUr kXV)K:֖^<-X+!,i+ˉ:÷(Z* N(g򺀡*(iR|-DC2EJ"B"q\QEDT, &Y8,gU]E)xyka *aM}ͱ㉫zd*/ftu y2lV8 ~'g;cz3RH+&mݦ}GFƄqa@1TXH QFy쓻-3νd kd# @$k;Nug UDļHi?>vI<ӳSk8?hӒͶ8_HQ"xU3ְB/;#_Ku0 P Ęd~x`"g0 NTMk9m@^ڱcz(AHMF}~hr RM ٺ&3!ҽ }@HҒ@

#includevoid main(){char string[81];int i,num=0;word=0;char c;gets(string[i];for(i=0;(c=string[i])!='\0';i++)if(c==' ') word=0;else if(word==0){word=1;num++;}printf("There are %d words in the line.\n",num)}
#include
void main()
{
char string[81];
int i,num=0;word=0;
char c;
gets(string[i];
for(i=0;(c=string[i])!='\0';i++)
if(c==' ') word=0;
else if(word==0)
{
word=1;
num++;
}
printf("There are %d words in the line.\n",num)
}

#includevoid main(){char string[81];int i,num=0;word=0;char c;gets(string[i];for(i=0;(c=string[i])!='\0';i++)if(c==' ') word=0;else if(word==0){word=1;num++;}printf("There are %d words in the line.\n",num)}
你的程序都有错误的说
#include
void main()
{
char string[81];
int i,num=0,word=0;
char c;
gets(string); /*这里必须用string,不能用string[i]*/
for(i=0;(c=string[i])!='\0';i++) /*假如字符串没有结尾,则继续判断*/
if(c==' ') word=0; /*如果为空格的话,将word赋值为0*/
else if(word==0) /*如果上一次判断时,c为空格,则word为0,此时将word赋值为1,num加1*/
{
word=1; /*意思就是,如果上一次遇到了空格,证明一个单词结束,num计数加1(这里有问题的,这个程序其实不太完美)*/
num++;
}
printf("There are %d words in the line.\n",num);
}