zoukankan      html  css  js  c++  java
  • 7.7 wordcnt.c 程序

    wordcnt.c 程序

    #include <stdio.h>
    #include <ctype.h>    // 为isspace() 函数提供原型
    #include <stdbool.h>  // 为bool、true、false提供定义
    #define STOP '|'
    int main(void)
    {
        char c;                 // 读入字符
        char prev;              // 读入的前一个字符
        long n_chars = 0L;      // 字符数
        int n_lines = 0;        // 行数
        int n_words = 0;        // 单词数
        int p_lines = 0;        // 不完整的行数
        bool inword = false;    // 如果c在单词中, inword 等于 true
        printf("Enter text to be analyzed (| to terminate):  
    ");
        prev = '
    ';            // 用于识别完整的行
        while ((c = getchar())  != STOP)
        {
            n_chars++;          // 统计字符
            if (c == '
    ')
                n_lines++;      // 统计行
            if (! isspace(c) && !inword)
            {
                inword = true;  // 开始一个新的单词
                n_words++;      // 统计单词
            }
            if (isspace(c) && inword)
                inword = false;  // 达到单词的末尾
            prev = c;            // 保存字符的值
        }
        if (prev != '
    ')
            p_lines = 1;
        printf("characters = %ld, words = %d, lines = %d, ",
                n_chars, n_words, n_lines);
        printf("partial lines = %d
    ", p_lines);
        return 0;
    }
  • 相关阅读:
    Python 包的概念
    EXCEL基础篇(二)
    EXCEL基础篇(一)
    JavaScript(四)Bom
    JavaScript(三)Dom查找、设置标签属性及内容、绑定事件
    erlang并发编程(二)
    OTP&ETS
    erlang中http请求
    erlang证书加密
    erlang并发编程
  • 原文地址:https://www.cnblogs.com/EisNULL/p/10700636.html
Copyright © 2011-2022 走看看