码迷,mamicode.com
首页 > 编程语言 > 详细

c语言实现wc功能

时间:2017-09-29 01:50:31      阅读:221      评论:0      收藏:0      [点我收藏+]

标签:std   cte   argv   main   ==   tchar   char   lines   stdio.h   

本随笔对网站http://blog.chinaunix.net/uid-22566367-id-381958.html有所借鉴

#include <stdio.h>


#define BEGIN 1;

int main(int argc, char *argv[])
{
    int characters, lines, words, state;
    char c;

    state = characters = lines = words = 0;
    while((c = getchar()) != ‘0‘) {
        characters++;
        if(c == ‘\n‘) {
            lines++;
            state = 0;
            continue;
        } else if(c == ‘ ‘) {
            state = 0;
            continue;
        } else if(c == ‘\t‘) {
            state = 0;
            continue;
        } else {
            if(state == 0) {
                state = BEGIN;
                words++;
            }
            continue;
        }
    }

    printf("%d characters. %d words. %d lines.\n", characters, words, lines);
}

c语言实现wc功能

标签:std   cte   argv   main   ==   tchar   char   lines   stdio.h   

原文地址:http://www.cnblogs.com/vonzc/p/7609153.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!