C语言刷题(1) 输入一行字符,统计有多少个单词,单词之间用空格隔开。

#include <stdio.h>
void main()
{
    int i;
    char a[100];
    char c;
    gets(a);
    int word =0 ,num=0;
    for(i = 0;((c = a[i])!='\0');i++)
    {
        if(c == ' ')
        {
            word = 0;
        }
        else if(word == 0)
        {
            word = 1;
            num++;
        }

    }
    printf("There are %d  words in this line",num);

}

发布了45 篇原创文章 · 获赞 7 · 访问量 1627

猜你喜欢

转载自blog.csdn.net/qq_38173631/article/details/103938131