马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- //字符分类统计函数
- #include<stdio.h>
- #include<string.h>
- void my_function(char ch[100])
- {
- int i,words=0,digits=0,space=0,others=0;
- for(i=0;i<strlen(ch);i++)
- {
- if((ch[i]>='a'&&ch[i]<='z')||(ch[i]>='A'&&ch[i]<='Z'))
- {
- words++;
- }
- else if(ch[i]>='0'&&ch[i]<='9')
- {
- digits++;
- }
- else if(ch[i]==' ')
- {
- space++;
- }
- else
- {
- others++;
- }
- }
- printf("字母有 %d 个\n数字有 %d 个\n空格有 %d 个\n其他字符有 %d个\n",words,digits,space,others);
- }
- int main()
- {
- char s[100];
- int i,words=0,digits=0,space=0,others=0;
- printf("请你输入一个字符串:");
- gets(s);
- my_function(s);
- return 0;
- }
复制代码 运行结果如下:
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。 |