任务是使用频率表(不区分大小写字母)将(给定文本文件)遇到的拉丁字符打印到文件 f1。该表必须按字母顺序排序。到目前为止,我的程序只计算字母 A。我在创建遍历整个字母表并将表格打印到另一个文件中的循环时遇到问题,你能帮我解决这些问题吗?
#include <stdio.h>
const char FILE_NAME[] = "yo.txt";
#include <stdlib.h>
#include <iostream>
using namespace std;
int main() {
int count = 0; /* number of characters seen */
FILE *in_file; /* input file */
/* character or EOF flag from input */
int ch;
in_file = fopen(FILE_NAME, "r");
if (in_file == NULL) {
printf("Cannot open %s\n", FILE_NAME);
system("Pause");
exit(8);
}
while (1) {
char cMyCharacter = 'A';
int value = (int)cMyCharacter;
ch = fgetc(in_file);
if (ch == EOF){
break;
}
int file_character = (int) ch;
if (file_character == value || file_character == value+ 32) {
count++;
}
}
printf("Number of characters in %s is %d\n", FILE_NAME, count);
char cMyCharacter = 'A';
int iMyAsciiValue = (int)cMyCharacter;
cout << iMyAsciiValue;
system("Pause");
fclose(in_file);
return 1;
}