|
发表于 2020-3-2 02:02:06
|
显示全部楼层
本帖最后由 jackz007 于 2020-3-2 02:14 编辑
- #include <stdio.h>
- main(void)
- {
- char c , num[256] ;
- int i , blank , digit , other ;
- for(blank = 0 , digit = 0 , other = 0 ; (c = getchar()) != EOF ;) {
- if(c >= '0' && c <= '9') num[digit ++] = c ;
- else if(c == '\t' || c == '\n' || c == ' ') blank ++ ;
- else other ++ ;
- }
- printf("数字有%d个\n" , digit) ;
- for(i = 0 ; i < digit ; i ++) printf("\t%c\n" , num[i]) ;
- printf("blank有 %d 个\n" , blank) ;
- printf("其他字符有 %d 个\n" , other) ;
- printf("\n") ;
- }
复制代码
编译、运行实况:
- C:\Bin>g++ -o x x.c
- C:\Bin>x
- #include <stdio.h>
- main(void)
- {
- char c , num[256] ;
- int i , blank , digit , other ;
- for(blank = 0 , digit = 0 , other = 0 ; (c = getchar()) != EOF ;) {
- if(c >= '0' && c <= '9') num[digit ++] = c ;
- else if(c == '\t' || c == '\n' || c == ' ') blank ++ ;
- else other ++ ;
- }
- printf("数字有%d个\n" , digit) ;
- for(i = 0 ; i < digit ; i ++) printf("\t%c\n" , num[i]) ;
- printf("blank有 %d 个\n" , blank) ;
- printf("其他字符有 %d 个\n" , other) ;
- printf("\n") ;
- }
- ^Z
- 数字有9个
- 2
- 5
- 6
- 0
- 0
- 0
- 0
- 9
- 0
- blank有 480 个
- 其他字符有 341 个
- C:\Bin>
复制代码 |
|