2000字范文,分享全网优秀范文,学习好帮手!
2000字范文 > c语言:(指针)输入一行文字 找出其中的大写字母 小写字母 数字 空格以及其他字符

c语言:(指针)输入一行文字 找出其中的大写字母 小写字母 数字 空格以及其他字符

时间:2022-07-08 05:10:05

相关推荐

c语言:(指针)输入一行文字 找出其中的大写字母 小写字母 数字 空格以及其他字符

c语言:(指针)输入一行文字,找出其中的大写字母,小写字母,数字,空格以及其他字符

#include<stdio.h>#include<stdlib.h>#include<string.h>void main() {char str[100];printf("请输入一行文字\n");fgets(str, 100, stdin);int space = 0;int litter = 0;int litters = 0;int num = 0;int other = 0;for (char* p = str; *p != '\0';++p) {if (*p == ' ') {space += 1; }else if (*p > 64 && *p < 91) {//大写字母 ASCII 64~91 litter += 1;}else if (*p > 97 && *p < 122) {//小写字母 ASCII 97~122 litters += 1;}else if (*p > 47 && *p < 58) {//数字 ASCII 0~9 num += 1;}else {if (*p != '\n') {//fgets()函数会在末尾自动加上\n,需要判断是否为换行符other += 1;}}}printf("空格的个数:%d\n", space);printf("大写英文字母个数:%d\n", litter);printf("小写英文字母个数:%d\n", litters);printf("数字的个数为:%d\n", num);printf("其他字符的个数:%d\n", other);}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。