c++ 文本处理

来源:百度知道 编辑:UC知道 时间:2024/06/28 05:53:58
有一个文件为in.txt,设计一个c++程序,统计in.txt中的每一个字符出现的次数,大小写不分。并把统计的结果输入到out.txt中。
希望高手赐教,最好附上源代码,万分感谢!

主要功能代码可以参考下面,实际上就是输入输出的处理。
FILE *infp = fopen("in.txt", "r");
FILE *outfp = fopen("out.txt", "w");
int res[26] = {0};

while (fscanf("%c", C) != EOF)
{
res[toLower(C) - 'a']++;
}
for (int i = 0; i < 26; i++)
{
fprintf(outfp, "%d\n", res[i]);
}

fclose(infp);
fclose(outfp);

1楼的代码不错!