题目

题目来源:桂林理工 - 877-C语言程序设计 - 2022年 - 第四题第4题
我的笨方法
| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 
 | #include <stdio.h>
 int main() {
 int chNum[26]={0};
 
 FILE *file = fopen("data.txt", "r");
 FILE *outputFile = fopen("data_bak.txt", "w");
 if (file == NULL || outputFile == NULL) {
 printf("文件打开有误\n");
 return 1;
 }
 
 int ch;
 while ((ch = getc(file)) != EOF) {
 if(ch>='a' && ch<='z'){
 chNum[ch-'a']++;
 }else if(ch>='A' && ch<='Z'){
 chNum[ch-'A']++;
 }else{
 fputc(ch, outputFile);
 }
 }
 
 // 关闭文件
 fclose(file);
 fclose(outputFile);
 
 for(int i=0;i<26;i++){
 printf("%c:%d ",i+'a',chNum[i]);
 }
 return 0;
 }
 
 | 
data.txt文件内容的例子
运行结果

