c语言编程练习题:7-141 统计一行文本的单词个数
作者:yunjinqi   类别:    日期:2023-05-31 17:21:11    阅读:108 次   消耗积分:0 分    

image.png

#include <stdio.h>

int main(){
    char c;
    char pre_c=' ';
    int count=0;
    while (scanf("%c",&c)!=EOF && c!='\n'){
        // printf("c=%c\n",c);
        if (pre_c!=' ' && c==' '){count++;}
        pre_c = c;
        
    }
    if (pre_c!=' ' && c=='\n'){count++;}
    if (pre_c!=' ' && c==' '){count++;}
    printf("%d",count);
    return 0;
}


版权所有,转载本站文章请注明出处:云子量化, http://www.woniunote.com/article/266
上一篇:c语言编程练习题:7-140 斐波那契数列第n项
下一篇:c语言编程练习题:7-142 判断上三角矩阵