C语言:统计一个文件中大写字符、小写字符、数字个数--++大小写数值金额统计自定义处理DIY

C语言:统计一个文件中大写字符、小写字符、数字个数

在这里插入图片描述
“Project15122.exe”: 已加载“C:\Windows\System32\sechost.dll”,已加载符号(去除源信息)。
“Project15122.exe”: 已加载“C:\Windows\System32\rpcrt4.dll”,已加载符号(去除源信息)。
“Project15122.exe”: 已加载“C:\Windows\System32\cryptbase.dll”,已加载符号(去除源信息)。
“Project15122.exe”: 已加载“C:\Windows\System32\bcryptprimitives.dll”,已加载符号(去除源信息)。
线程 ‘Win64 线程’ (0x3674) 已退出,返回值为 0 (0x0)。
线程 ‘Win64 线程’ (0x206c) 已退出,返回值为 0 (0x0)。
线程 ‘Win64 线程’ (0x3264) 已退出,返回值为 0 (0x0)。
“Project15122.exe”: 已加载“C:\Windows\System32\kernel.appcore.dll”,已加载符号(去除源信息)。
程序“[10208] Project15122.exe: 本机”已退出,返回值为 0 (0x0)。

代码如下:

#include <iostream>
#include <fstream>
using namespace std;
void chapterstatistic()
{
	printf_s("统计文件开始\r\n");
	char *path = "E:\\VS2015\\shujuji\\shuju_SVM\\SAVE_wine.txt";
	FILE *f;
	int r = fopen_s(&f, path, "r");
	if (r>0)
	{
		printf_s("读取文件错误");
	}
	int capletter = 0, lowercase = 0, num = 0, other = 0;
	char temp = fgetc(f);
	while (!feof(f))
	{
		if (temp >= 'a' && temp <= 'z')
		{
			lowercase++;
		}
		else if (temp >= 'A' && temp <= 'Z')
		{
			capletter++;
		}
		else if (temp >= '0' && temp <= '9')
		{
			num++;
		}
		else
		{
			other++;
		}
		temp = fgetc(f);
	}
	printf_s("大写字符:%d  小写字符个数:%d  数字个数:%d   其他字符个数:%d", capletter, lowercase, num, other);

	fclose(f);
	printf_s("统计文件结束\r\n");
}

int main()
{
	chapterstatistic();
	system("pause");

}

效果如图:
在这里插入图片描述
另外的,附上数字大小写数值金额统计自定义处理DIY

int csdsdd()
{
	int money;
	int i = 0;
	int count = 0;//记录用户输入数字位数
	int money_s[N];
	int temp = 0;//临时存放变量
	char num[10][4] = { "零","壹","贰","叁","肆","伍","陆","柒","捌","玖" };
	char unit[6][8] = { "拾万","万","仟","佰","拾","元整" };
	//一个中文占4个字节

	printf("请输入整数为6位及以内的金额(小数点后忽略不计):\n");
	for (;;)
	{
		scanf("%d", &money);
		if (money / 1000000 >= 1)
		{
			printf("输入有误!\n");
		}
		else { break; }
	}
	printf("您输入的金额为:%d。\n", money);
	for (i = 0; i<10; i++)//测试num数组正确性
	{
		printf("num数组第%d位为:%s\n", i + 1, num[i]);
	}
	for (i = 0; i<6; i++)//测试unit数组正确性
	{
		printf("数组第%d位为:%s\n", i + 1, unit[i]);
	}
	for (i = 0; i<N; i++)//取出用户每一位数字
	{
		money_s[i] = money % 10;
		money /= 10;
		count++;
		if (money == 0)
		{
			break;
		};
	}
	for (i = 0; i<count; i++)//打印数组中用户每一位数字
	{
		printf("%d\n", money_s[count - i - 1]);
	};
	printf("\n");
	for (i = 0; i<count; i++)
	{
		temp = money_s[count - i - 1];
		printf("%s\t", num[temp]);
		printf("%s\t", unit[6 - count + i]);
		temp = 0;
	}
	return 0;
}

在这里插入图片描述
整体效果如图:
在这里插入图片描述
全部代码运行如下:

#include <iostream>
#include <fstream>
using namespace std;
#include <stdio.h>
#include <stdlib.h>
#define N 6

void chapterstatistic()
{
	printf_s("统计文件开始\r\n");
	char *path = "E:\\VS2015\\shujuji\\shuju_SVM\\save_data_1V.txt";
	FILE *f;
	int r = fopen_s(&f, path, "r");
	if (r>0)
	{
		printf_s("读取文件错误");
	}
	int capletter = 0, lowercase = 0, num = 0, other = 0;
	char temp = fgetc(f);
	while (!feof(f))
	{
		if (temp >= 'a' && temp <= 'z')
		{
			lowercase++;
		}
		else if (temp >= 'A' && temp <= 'Z')
		{
			capletter++;
		}
		else if (temp >= '0' && temp <= '9')
		{
			num++;
		}
		else
		{
			other++;
		}
		temp = fgetc(f);
	}
	printf_s("大写字符:%d  小写字符个数:%d  数字个数:%d   其他字符个数:%d", capletter, lowercase, num, other);

	fclose(f);
	printf_s("统计文件结束\r\n");
}

int csdsdd()
{
	int money;
	int i = 0;
	int count = 0;//记录用户输入数字位数
	int money_s[N];
	int temp = 0;//临时存放变量
	char num[10][4] = { "零","壹","贰","叁","肆","伍","陆","柒","捌","玖" };
	char unit[6][8] = { "拾万","万","仟","佰","拾","元整" };
	//一个中文占4个字节

	printf("请输入整数为6位及以内的金额(小数点后忽略不计):\n");
	for (;;)
	{
		scanf("%d", &money);
		if (money / 1000000 >= 1)
		{
			printf("输入有误!\n");
		}
		else { break; }
	}
	printf("您输入的金额为:%d。\n", money);
	for (i = 0; i<10; i++)//测试num数组正确性
	{
		printf("num数组第%d位为:%s\n", i + 1, num[i]);
	}
	for (i = 0; i<6; i++)//测试unit数组正确性
	{
		printf("数组第%d位为:%s\n", i + 1, unit[i]);
	}
	for (i = 0; i<N; i++)//取出用户每一位数字
	{
		money_s[i] = money % 10;
		money /= 10;
		count++;
		if (money == 0)
		{
			break;
		};
	}
	for (i = 0; i<count; i++)//打印数组中用户每一位数字
	{
		printf("%d\n", money_s[count - i - 1]);
	};
	printf("\n");
	for (i = 0; i<count; i++)
	{
		temp = money_s[count - i - 1];
		printf("%s\t", num[temp]);
		printf("%s\t", unit[6 - count + i]);
		temp = 0;
	}
	return 0;
}

int main()
{
	chapterstatistic();
	csdsdd();
	system("pause");

}
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

海宝7号

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值