码迷,mamicode.com
首页 > 其他好文 > 详细

输入一行统计其中单词的个数

时间:2015-06-06 17:49:38      阅读:99      评论:0      收藏:0      [点我收藏+]

标签:

#include <string.h>
#include <stdio.h>
int main()
{
    int count = 1;
    char str[1024];
    int i=0;
    int j =0;
    char ch=0;
    while(ch != \n)    //输入一串英文
    {
            ch = getchar();
            str[j]=ch;
            j++;
    }
    str[j]=\0;    
    
    while(str[i]!=\0)    //统计单词个数
    {
            if(str[i]== &&str[i+1]!= &&str[i+1]!=\0)
            count ++; 
            i++;
    }
    printf("%d\n",count);
}

测试结果:

I am going to shoping!
5


------------------
(program exited with code: 0)
Press return to continue

 

输入一行统计其中单词的个数

标签:

原文地址:http://www.cnblogs.com/wystan/p/4556869.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!