博客
关于我
【C语言】统计字符数
阅读量:681 次
发布时间:2019-03-17

本文共 714 字,大约阅读时间需要 2 分钟。

   
#include
int letter_count=0,num_count=0,other_count=0;//用于统计字符串中字母、数字和其他字符的数量void char_count(char *str){ int i=0; while(*(str+i) != '\0'){ char c = *(str+i); if( c >= '0' && c <= '9') num_count++; else if( (c >= 'A' && c <='Z') || (c >= 'a' && c <= 'z')) letter_count++; else other_count++; i++; }}int main() { char str[50]; gets(str); char_count(str); printf("字母数为:%d\t数字数:%d\t其他字符数为:%d\n",letter_count,num_count,other_count); system("pause"); return EXIT_SUCCESS;}

注:以上代码描述了一个用于统计字符类型的程序,适用于处理字符串中的不同字符分类统计场景。设置三个计数器分别记录字母、数字和其他字符的数量,可根据实际需求进行修改和扩展,支持多种字符分类识别功能。

转载地址:http://yizhz.baihongyu.com/

你可能感兴趣的文章
others
查看>>
Oulipo
查看>>
Outlook 2010 Inside Out
查看>>
outlook 2016 接收发送无法及时收下邮件,如何更改接收时间?
查看>>
Outlook Express could not be started
查看>>
outlook express 故障
查看>>
outlook gmail setting
查看>>
spring自定义线程池 逻辑 配置 ThreadPoolTaskExecutor corePoolSize maxPoolSize queueCapacity rejectedExecutionHa
查看>>
Outlookbar-style menu interface
查看>>
outlook中XXX.xls附件无法打开解决办法
查看>>
Outlook存档
查看>>
Outlook替代Hotmail:社交很重要,但邮箱是根本
查看>>
Outlook邮箱怎么方便地发送超大附件?
查看>>
outputStream转inputStream
查看>>
overflow:hidden不生效问题
查看>>
overlay(VLAN,VxLAN)、underlay网络、大二层概述
查看>>
Overload和Override的区别?
查看>>
Ovirt添加ISO存储域
查看>>
OWASP 2025 年 10 大漏洞 – 被利用/发现的最关键弱点,从零基础到精通,收藏这篇就够了!
查看>>
OWASP漏洞原理启航(第一课)
查看>>