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);}