现在的位置: 首页 > 综合 > 正文

多少单词

2017年11月22日 ⁄ 综合 ⁄ 共 406字 ⁄ 字号 评论关闭
#include <stdio.h>
#include <stdlib.h>
#include<string.h>
char ch[1000000];
int main ()
{
    int word=0,m=0,i;  
    char c;
    gets(ch);       //scanf输入字符串当字符串中含有空格的时候,空格后面的部分将不会被读入;而用gets则可以
    //scanf("%s",ch);
    //printf("%d\n",strlen(ch));
    for(i=0;(c=ch[i])!='\0';i++)
    if(c==' ')word=0;
    else if(word==0)
    {
         word=1;
         m++;
         }
    printf("%d\n",m);
    system("pause");
    return 0;
    } 

 

scanf输入字符串当字符串中含有空格的时候,空格后面的部分将不会被读入,但当空格在前面则表示字符串未开始;而用gets则读入所有字符。

 

gets输入:

 

 

scanf输入:

 

 

【上篇】
【下篇】

抱歉!评论已关闭.