(C语言)有一篇文章,共有3行文字,每行有80个字符。要求统计出其中英文大写字母,小写字母,数字,空格,其他字符的个数

有一篇文章,共有3行文字,每行有80个字符。要求统计出其中英文大写字母,小写字母,数字,空格,其他字符的个数

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
void fun(char str[][80]) {
	int space = 0;
	int capital = 0;
	int lowercase = 0;
	int num = 0;
	int other = 0;
	for (int i = 0; i < 3; ++i) {
		for (int j = 0; j < 80; ++j) {
			if (str[i][j] == ' ') {
				space++;
			}
			else if (str[i][j] > 64 && str[i][j] < 91) {
				capital++;
			}
			else if (str[i][j] > 96 && str[i][j] < 123) {
				lowercase++;
			}
			else if (str[i][j] > 47 && str[i][j] < 58) {
				num++;
			}
			else if(str[i][j] != '\0'){
				other++;
			}
		}
	}
	printf("大写字母个数为%d\n小写字母个数为%d\n空格个数为%d\n数字个数为%d\n其他字符个数为%d\n", capital, lowercase, space, num, other);
}
void main() {
	char str[3][80] = { {"Mr.Johnson had never been up in an aerophane before and he had read a lot about"},
						{" air accidents, so one day when a friend offered to take him for a ride in his "},
						{"won small phane, Mr. Johnson was very worried about accepting. Finally, 1234 56"} };
	printf("文章为:\n");
	for (int i = 0; i < 3; ++i) {
		printf("%s", str[i]);
	}
	printf("\n");
	fun(str);
	system("pause");
}

在这里插入图片描述

  • 32
    点赞
  • 119
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值