博客
关于我
【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/

你可能感兴趣的文章
UML— 用例图
查看>>
Oracle Schema Objects——Tables——Table Compression
查看>>
oracle scott趣事
查看>>
oracle script
查看>>
Oracle select表要带双引号的原因
查看>>
Oracle SOA Suit Adapter
查看>>
Oracle Spatial GeoRaster 金字塔栅格存储
查看>>
Oracle spatial 周边查询SQL
查看>>
Oracle Spatial空间数据库建立
查看>>
UML— 活动图
查看>>
oracle sqlplus已停止工作,安装完成客户端后sqlplus报“段错误”
查看>>
oracle SQLserver 函数
查看>>
oracle sql分组(group,根据多个内容分组)在select之后from之前 再进行select查询,复杂子查询的使用
查看>>
UML— 时序图
查看>>
Oracle Statspack分析报告详解(一)
查看>>
oracle tirger_在Oracle中,临时表和全局临时表有什么区别?
查看>>
Oracle Validated Configurations 安装使用 说明
查看>>
oracle where 条件的执行顺序分析1
查看>>
oracle 中的 CONCAT,substring ,MINUS 用法
查看>>
Oracle 中的 decode
查看>>