请大家帮帮忙,这题目想了很久,百度了还是没一点头绪。
本帖最后由 风之残月 于 2014-11-10 10:22 编辑编写一个用来统计输入的各个数字丶空白符(空格,制表符,换行符)以及所有其他字符出现次数的程序。
把数字放入num
空白符放入blank
以及所有其他的字符a,b,c,%等等放入others.
1 #include <stdio.h>
2 #include <ctype.h>
3 int main(int argc, char **argv)
4 {
5 int ch = 0, number = 0, blank = 0, other = 0;
6 printf("Enter a text: ");
7 while((ch = getchar()) != EOF)
8 {
9 if(isdigit(ch))
10 number++;
11 else if(isspace(ch))
12 blank++;
13 else
14 other++;
15 }
16 printf("number: %d\n blank: %d\n other: %d\n", number, blank, other);
17 return 0;
18 }
分别放入里面,在打印出来。 非常感谢。
页:
[1]