效果如图:
文件整理开始
小写字母转换为大写:s到S
小写字母转换为大写:d到D
小写字母转换为大写:f到F
大写字母转换为小写:F到f
大写字母转换为小写:S到s
小写字母转换为大写:s到S
小写字母转换为大写:f到F
小写字母转换为大写:s到S
小写字母转换为大写:d到D
小写字母转换为大写:f到F
大写字母转换为小写:D到d
小写字母转换为大写:s到S
小写字母转换为大写:d到D
小写字母转换为大写:f到F
小写字母转换为大写:h到H
大写字母转换为小写:F到f
大写字母转换为小写:S到s
大写字母转换为小写:D到d
小写字母转换为大写:a到A
小写字母转换为大写:d到D
大写字母转换为小写:S到s
大写字符:7
小写字符个数:14
统计文件完毕
请按任意键继续. . .
源码如下:
000、头文件部分:
#include <iostream>
#include <fstream>
#include<iomanip>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
001子函数部分
void chapterSStatistic(char *path032) /*统计一个文件中的大写字母 小写字母的个数并转换大小写*/
{
printf_s("文件整理开始\r\n");
FILE *frrt;
int capletter = 0, lowercase = 0, num = 0, other = 0;
int tres = 0, TRES = 0;
frrt = fopen(path032, "r");
char temp,tmpp5;
while (!feof(frrt))
{
temp = fgetc(frrt); //中间变量,一次读取一个
if (temp >= 'a' && temp <= 'z')
{
lowercase++;
tmpp5 = temp;
tmpp5 = tmpp5 - 32;
printf_s("小写字母转换为大写:%c到%c\n", temp,tmpp5);
}
else if (temp >= 'A' && temp <= 'Z')
{
capletter++;
tmpp5 = temp;
tmpp5 = tmpp5 + 32;
printf_s("大写字母转换为小写:%c到%c\n", temp, tmpp5);
}
else if (temp >= '0' && temp <= '9')
{
num++;
}
else
{
other++;
}
}
fclose(frrt);
printf_s("大写字符:%d\n小写字符个数:%d", capletter, lowercase);
printf_s("\n统计文件完毕\r\n");
}
002、主函数部分:
//主函数入口主函数入口主函数入口主函数入口主函数入口主函数入口主函数入口主函数入口
int main()
{
char *path001 = "E:\\VS2015\\shujuji\\shuju_SVM\\22554.txt";
chapterSStatistic(path001);
system("pause");
}