zoukankan      html  css  js  c++  java
  • c语言实现wc功能

    本随笔对网站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 == ' ') {
                lines++;
                state = 0;
                continue;
            } else if(c == ' ') {
                state = 0;
                continue;
            } else if(c == ' ') {
                state = 0;
                continue;
            } else {
                if(state == 0) {
                    state = BEGIN;
                    words++;
                }
                continue;
            }
        }

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

  • 相关阅读:
    ioremap函数
    kmalloc、kzalloc和vmalloc
    C语言 snprintf函数
    C语言 memset函数
    消息队列
    mount -a
    linux系统查看服务状态和启动停止服务
    Java中创建对象的内存图
    Java中数组在内存中的图解
    socket编程(Java实现)
  • 原文地址:https://www.cnblogs.com/vonzc/p/7609153.html
Copyright © 2011-2022 走看看