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

你可能感兴趣的文章
Python 中的... 三点、箭头(->)、/ 分别的作用
查看>>
python读取json数据的id_python处理JSON数据
查看>>
Python 中的Duck Typing
查看>>
Python 中的for in 遍历生成字典、添加判断条件if
查看>>
Python 中的Lock与RLock
查看>>
Python 中的range(),arange()函数
查看>>
Python 中的内存管理机制
查看>>
Python 中的函数包装器:模型运行时和调试
查看>>
Python 中的列表理解和 lambda
查看>>
Python 中的多层for in嵌套循环使用
查看>>
Python 中的多线程(01/4)
查看>>
Python 中的多进程(01/2):简介
查看>>
Python 中的多进程(02/2):进程之间的通信)
查看>>
Python 中的字符串、列表、元组和字典数据类型的特点和使用场景
查看>>
Python 中的属性访问器是什么?如何使用 @property 装饰器?
查看>>
Python 中的带宽限制
查看>>
Python 中的机器学习简介:多项式回归
查看>>
python读取grib2数据_用Python加载grib2文件
查看>>
Python 中的注意点_s2
查看>>
Python读取Excel的几种工具包(附Demo)
查看>>