码迷,mamicode.com
首页 > 编程语言 > 详细

C语言 统计一串字符中空格键、Tab键、回车键、字母、数字及其他字符的个数(Ctrl+Z终止输入)

时间:2018-03-18 12:04:10      阅读:254      评论:0      收藏:0      [点我收藏+]

标签:字符   ctrl   ase   image   character   bsp   img   i++   www   

 //凯鲁嘎吉 - 博客园 http://www.cnblogs.com/kailugaji/ 

 1 #include<stdio.h>
 2 
 3 void main(){
 4     int c, letter=0, num=0, blank=0, tab=0, enter=0, other=0 ,i=0, sum=0;
 5     printf("Please input a string:\n");
 6     while((c=getchar())!=EOF){
 7         sum++;
 8         if(c== ){
 9             ++blank;  //空格键的个数
10         }
11         else if(c==\t){
12             ++tab;   //Tab键的个数
13         }
14         else if(c==\n){
15             ++enter;   //回车键的个数
16         }
17         else if((c>=A && c<=Z) || (c>=a && c<=z)){
18             ++letter;    //字母的个数
19         }
20         else if(c>=0 && c<=9){
21             ++num;      //数字的个数
22         }
23         else ++other;     //其他字符的个数
24         i++;
25     }
26     printf("There are %d characters\n", sum);
27     printf("blank=%d, Tab=%d, Enter=%d, letter=%d, number=%d ,other=%d\n",blank, tab, enter, letter, num, other);
28 
29 }

结果为:

技术分享图片

 

C语言 统计一串字符中空格键、Tab键、回车键、字母、数字及其他字符的个数(Ctrl+Z终止输入)

标签:字符   ctrl   ase   image   character   bsp   img   i++   www   

原文地址:https://www.cnblogs.com/kailugaji/p/8594385.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!