字符类型统计器(小例子)

来源:互联网 发布:云计算三种模式 编辑:程序博客网 时间:2024/05/01 01:22

要求:统计空格符、制表符、回车符的个数

 

代码:

#include <stdio.h>#include <stdlib.h>int main(void){int c;       //EOF是一个整型值int space;int table;int enter;space = table = enter = 0;while ((c=getchar())!=EOF && (c==' '?++space:1) && (c=='\t'?++table:1) && (c=='\n'?++enter:1));printf("space:%d\n", space);printf("table:%d\n", table);printf("enter:%d\n", enter);system("PAUSE");return 0;}


注意:回车要在新的一行,才能结束(getchar()函数的要求)

 

欢迎大家提出宝贵的意见!

 

 

0 0