C语言统计一串字符中空格键、Tab键、回车键、字母、数字及其他字
发布时间:2020-12-15 01:18:08 所属栏目:C语言 来源:网络整理
导读:具体代码如下所述: #includestdio.hvoid main(){ int c,letter=0,num=0,blank=0,tab=0,enter=0,other=0,i=0,sum=0; printf("Please input a string:n"); while((c=getchar())!=EOF){ sum++; if(c==' '){ ++blank; //空格键的个数 } else if(c=='t'){ ++ta
具体代码如下所述: #include<stdio.h> void main(){ int c,letter=0,num=0,blank=0,tab=0,enter=0,other=0,i=0,sum=0; printf("Please input a string:n"); while((c=getchar())!=EOF){ sum++; if(c==' '){ ++blank; //空格键的个数 } else if(c=='t'){ ++tab; //Tab键的个数 } else if(c=='n'){ ++enter; //回车键的个数 } else if((c>='A' && c<='Z') || (c>='a' && c<='z')){ ++letter; //字母的个数 } else if(c>='0' && c<='9'){ ++num; //数字的个数 } else ++other; //其他字符的个数 i++; } printf("There are %d charactersn",sum); printf("blank=%d,Tab=%d,Enter=%d,letter=%d,number=%d,other=%dn",blank,tab,enter,letter,num,other); } 结果为: 总结 以上所述是小编给大家介绍的C语言统计一串字符中空格键、Tab键、回车键、字母、数字及其他字符的个数(Ctrl+Z终止输入) ,希望对大家有所帮助,如果大家有任何疑问欢迎 您可能感兴趣的文章:
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |