700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > (C语言)(用指针方法处理)输入一行文字 找出其中大写字母 小写字母 空格 数字以及

(C语言)(用指针方法处理)输入一行文字 找出其中大写字母 小写字母 空格 数字以及

时间:2018-12-06 07:26:57

相关推荐

(C语言)(用指针方法处理)输入一行文字 找出其中大写字母 小写字母 空格 数字以及

(用指针方法处理)输入一行文字,找出其中大写字母,小写字母,空格,数字以及其他字符各有多少

#include<stdio.h>#include<stdlib.h>#include<string.h>#define M 1024void main() {char str[M];fgets(str, M, stdin);int space = 0;int capital = 0;int lowercase = 0;int num = 0;int other = 0;for (char* p = str; *p != '\0';++p) {if (*p == ' ') {space += 1;}else if (*p > 64 && *p < 91) {capital += 1;}else if (*p > 96 && *p < 123) {lowercase += 1;}else if (*p > 47 && *p < 58) {num += 1;}else {if (*p != '\n') {//因为fgets()函数会在末尾自动加上\n,影响判断结果,需要判断是否为换行符other += 1;}}}printf("空格的个数为:%d\n", space);printf("大写英文字母的个数为:%d\n", capital);printf("小写英文字母的个数为:%d\n", capital);printf("数字的个数为:%d\n", num);printf("其他字符的个数为:%d\n", other);system("pause");}

(C语言)(用指针方法处理)输入一行文字 找出其中大写字母 小写字母 空格 数字以及其他字符各有多少

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