要求:统计空格符、制表符、回车符的个数
代码:
#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()函数的要求)
欢迎大家提出宝贵的意见!