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. Hash算法入门指南(聊点不一样的算法人生)

    前言 很多人到现在为止都总是问我算法该怎么学啊,数据结构好难啊怎么的,学习难度被莫名的夸大了,其实不然.对于一个学计算机相关专业的人都知道,数据结构是大学的一门必修课,数据结构与算法是基础,却常常容易 ...

  2. Python的IO编程

    原文传送门:请点击 原文传送门:请点击

  3. python2.7练习小例子(二)

        2):题目:企业发放的奖金根据利润提成.利润(I)低于或等于10万元时,奖金可提10%:利润高于10万元,低于20万元时,低于10万元的部分按10%提成,高于10万元的部分,可提成7.5%:2 ...

  4. 阿里 & 酷家乐:实习生面试

    最近海投了十家公司,暂时有阿里两面(已凉).酷家乐两面(大概凉了).网易一面.前两个都是基础知识发挥得还可以,两家公司二面都凉凉. 阿里一面(3.21 26min) 刚好买了中饭回宿舍打开正准备吃的时 ...

  5. 搭建 RabbitMQ Server 高可用集群

    阅读目录: 准备工作 搭建 RabbitMQ Server 单机版 RabbitMQ Server 高可用集群相关概念 搭建 RabbitMQ Server 高可用集群 搭建 HAProxy 负载均衡 ...

  6. JavaScript正则表达式模式匹配(5)——特殊字符匹配、换行模式

    特殊字符匹配 var pattern=/\[/; // 用\符号来转义正则里的特殊字符才能匹配 var str='['; alert(pattern.test(str)); 换行模式 var patt ...

  7. Kali安装使用文泉驿字体

    安装文泉驿字体 Kali选择"简体中文"安装后,在终端等地方发现字体总有重叠,只要安装中文字体即可,这里推荐文泉驿字体.文泉驿是一个以开发开源.免费中文电子资源--如汉字字体.词库 ...

  8. JavaScript 比较和逻辑运算符

    比较和逻辑运算符用于测试 true 或者 false. 比较运算符 比较运算符在逻辑语句中使用,以测定变量或值是否相等. 给定 x=5,下面的表格解释了比较运算符: 实例 »实例 » 大于 大于或等于 ...

  9. 分别用face++和百度获取人脸属性(python单机版)

    称之为单机版,主要是相对于调用摄像头实时识别而言.本篇主要py2下利用face++和百度接口获取本地图片中的人脸属性,并按照一定格式保存数据. face++版 face++是刚注册的,只能用一个试用的 ...

  10. springMVC源码分析--HandlerMethodReturnValueHandlerComposite返回值解析器集合(二)

    在上一篇博客springMVC源码分析--HandlerMethodReturnValueHandler返回值解析器(一)我们介绍了返回值解析器HandlerMethodReturnValueHand ...