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

你可能感兴趣的文章
Oracle 数据库常用SQL语句(1)
查看>>
Oracle 数据库特殊查询总结
查看>>
Oracle 数据类型
查看>>
Oracle 数据自动备份 通过EXP备份
查看>>
oracle 数据迁移 怎么保证 和原表的数据顺序一致_一个比传统数据库快 1001000 倍的数据库,来看一看?...
查看>>
oracle 时间函数
查看>>
oracle 时间转化函数及常见函数 .
查看>>
Oracle 权限(grant、revoke)
查看>>
oracle 查询clob
查看>>
Oracle 比较 B-tree 和 Bitmap 索引
查看>>
Oracle 注意点大全
查看>>
UML- 组件图(构件图)
查看>>
oracle 用户与锁
查看>>
oracle 由32位迁移到64位的问题
查看>>
oracle 监听器的工作原理
查看>>
oracle 行列转换
查看>>
oracle 行转列
查看>>
Oracle 表
查看>>
oracle 课堂笔记
查看>>
Oracle 返回结果集的 存储过程
查看>>