This is a simple C program which can count input lines, words and chars. But the number of words are not very strict. It likes simple wc command.

#include<stdio.h>

/* 简单的统计行数,单词数目,字符个数等
   my_wc.c by orangleliu
*/

int main()
{
    int c, nl, nw, nc, flag;
    nl = nw = nc =0;

    while((c = getchar()) != EOF)
    {
       ++nc;
       if( c == '\n' )
           ++nl;

       if( c == ' '|| c == '\t' || c == '\n')
            flag = 1;
       else if ( flag == 1){
            ++nw;
            flag = 0;
       }
    }

    printf("line %d words %d chars %d \n", nl, nw, nc);
}

res

lzz-rmbp|file # cat my_wc.c|./a.out
line 25 words 68 chars 447

[C]simple code of count input lines,words,chars的更多相关文章

  1. Entity Framework Code-First(4):Simple Code First Example

    Simple Code First Example: Let's assume that we want to create a simple application for XYZ School. ...

  2. 1.2 Simple Code!(翻译)

    Simple Code! 简洁编码 Playing football is very simple, but playing simple football is the hardest thing ...

  3. Python: simple code

    # !/usr/bin/env python3.6 # -*- coding: utf-8 -*- # visual studio 2017 # 2019 10 12 Geovin Du print ...

  4. C lang:character input and output (I/O)

    Xx_Introduction Character input and output is by more line character conpose of the text flow  Defin ...

  5. PHP命令行模式基本介绍

      首先要保证php在cli模式下可用,php –v会返回PHP的版本号. [gaojian3@log001 ~]$ php -v PHP (cli) (built: Aug ::) Copyrigh ...

  6. php命令行用法简介

    Php是一个非常流行的web服务端脚本语言.其实,php不仅仅可以在web服务器中充当重要角色.在命令行一样可以执行. 本文中,笔者为各位介绍下php在命令行中的使用方法. 1.  查看php的版本. ...

  7. jQuery选择器中,通配符[id^='code']input[id$='code'][id*='code']

     1.选择器 (1)通配符: $("input[id^='code']");//id属性以code开始的所有input标签 $("input[id$='code']&qu ...

  8. Code Complete阅读笔记(二)

    2015-03-06   328   Unusual Data Types    ——You can carry this technique to extremes,putting all the ...

  9. 7. Input and Output

    7. Input and Output There are several ways to present the output of a program; data can be printed i ...

随机推荐

  1. Java并发编程:JMM(Java内存模型)和volatile

    1. 并发编程的3个概念 并发编程时,要想并发程序正确地执行,必须要保证原子性.可见性和有序性.只要有一个没有被保证,就有可能会导致程序运行不正确. 1.1. 原子性 原子性:即一个或多个操作要么全部 ...

  2. Saltstack基础

    salt介绍 salt简单介绍 一个基础平台管理工具 一个配置管理系统,能够维护预定义状态的远程节点 一个分布式远程执行系统,用来在远程节点上执行命令和查询数据 salt的核心功能 使命令发送到远程系 ...

  3. MySQL插件实现浅析——插件的调用

    一. MySQL中的动态插件 最初想到这个问题是在学习mysql半同步复制相关问题的时候,为何在mysql运行时install半同步插件并开启后就能起到作用,他是如何让事务停下来等待的.安装插件的时候 ...

  4. 修改firefox的默认缩放比

    我们在使用firefox时,发现页面的缩放比只能一个一个手动调整,当跳转到新的页面时默认缩放比又还原了,这个时候又要重新调整,相当不方便. 下面介绍修改默认缩放比的方法: 首先,打开firefox,然 ...

  5. div,margin,padding

    <!-- 类比礼品盒里装方块月饼.月饼的食用部分(我们把它称之为月饼肉身)要装在小包装盒里,月饼肉身即为content.月饼肉身与直接包裹它的小包装盒(我们把它叫做月饼的衣服)之间的距离叫pad ...

  6. 毕业回馈-89c51之定时器/计数器(Timer/Count)

    今天分享的是89c51系列单片机的内部资源定时器/计数器,在所有的嵌入式系统中都包含这两个内部功能. 首先先了解几个定时器/计数器相关的概念: •时钟周期:时钟周期 T 是时序中最小的时间单位,具体计 ...

  7. 阿里云linux下web服务器配置

    markdown截图不方便,本教程不用markdown编写 首先参考文章 https://www.jianshu.com/p/2604e53a7f6a?from=singlemessage 安装完后无 ...

  8. CRM客户关系管理系统(七)

    第七章.动态modelform功能实现  7.1.动态modelform的实现 (1)给第一列添加一个a标签 kingadmintag.py (2)kingadmin/urls.py urlpatte ...

  9. GDAL C#读取shp中文属性值乱码问题

    GDAL的C#版本读取shp中,如果属性值中含有中文,读出来有可能是乱码的问题,根据SWIG生成的C#代码调试发现问题所在,在Ogr.cs文件中有这么一个函数,代码如下: internal stati ...

  10. API得到Windows版本

    API得到Windows版本 /** * Windows Version * https://msdn.microsoft.com/en-us/library/windows/desktop/dn48 ...