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

c程序设计语言笔记001

时间:2014-11-27 20:27:06      阅读:187      评论:0      收藏:0      [点我收藏+]

标签:style   blog   io   ar   color   sp   div   log   bs   

统计输入行数

# include<stdio.h>
main ()
{
    int c,nl;
    nl=0;
    while ((c=getchar())!=EOF)
    {
        if(c==\n)
            ++nl;
    }
    printf("%d\n",nl);
}

单词计数 统计输入的函数nl 单词数nw 字符数nc

# include<stdio.h>
//单词计数 统计输入的函数nl 单词数nw 字符数nc
#define IN 1
#define OUT 0
main ()
{
    int c,nl,nw,nc,state;
    nl=nc=nw=0;
    state=OUT;
    while ((c=getchar())!=EOF)
    {
        ++nc;//字符数
        if(c==\n)
            ++nl;//统计行数
        if(c==  || c== \n || c==\t )
            state =OUT;
        else if(state ==OUT)
        {
            state =IN;
            ++nw;//单词数
        }
    }
    printf("%d  %d  %d\n",nl,nw,nc);
}

 

c程序设计语言笔记001

标签:style   blog   io   ar   color   sp   div   log   bs   

原文地址:http://www.cnblogs.com/220l/p/4127015.html

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