首页 > 其他 > 详细

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

时间:2015-06-06 17:46:56      阅读:218      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!