为了统计我们所输入的字符进行统计,一般我们都会编写一个程序进行统计,一般的原理就是。循环录入字符当遇到结束符号的时候停止结束,在循环的外部定义变量,根据ascill码,对录入的字符进行统计。代码如下:
- #include <string.h>
-
#include <stdio.h>
-
-
int main(int argc, char* argv[])
-
{
-
char c;
-
int space = 0, table = 0, enter = 0;
-
printf("please input a string:\n");
-
scanf("%c",&c);
-
-
while(c != EOF)
-
{
-
switch(c)
-
{
-
case 32: space++; break;
-
case 9: table++; break;
-
case 10: enter++; break;
-
default:break;
-
}
-
scanf("%c",&c);
-
}
-
-
printf("the number of space:%d\n", space);
-
printf("the number of table:%d\n", table);
-
printf("the number of enter:%d\n", enter);
-
getchar();
-
return 0;
-
}
阅读(1342) | 评论(0) | 转发(0) |