首页 > 编程语言 > 详细

c语言中统计单词数目程序

时间:2021-08-22 18:47:50      阅读:9      评论:0      收藏:0      [点我收藏+]

 

1、

#include <stdio.h>
#include <ctype.h>
#include <stdbool.h>
#define STOP ‘|‘

int main(void)
{
    char ch;
    char prep;
    long n_ch = 0L;
    int n_lines = 0;
    int n_words = 0;
    int n_p_line;
    bool inword = false;
    
    while((ch = getchar()) != STOP)
    {
        n_ch++;
        if(ch == \n)
            n_lines++;
        if(!isspace(ch) && !inword)
        {
            inword = true;
            n_words++;
        }
        if(isspace(ch) && inword)
            inword = false;
        prep = ch;
    }
    if(prep != \n)
        n_p_line = 1;
    
    printf("n_ch    : %ld\n", n_ch);
    printf("n_lines : %d\n", n_lines);
    printf("n_words : %d\n", n_words);
    printf("n_p_line: %d\n", n_p_line);
    
    return 0;
}

技术分享图片

 

c语言中统计单词数目程序

原文:https://www.cnblogs.com/liujiaxin2018/p/15172387.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!