我在使用这段代码时遇到了一些问题(见下文)。无论我输入什么文件名,我都会得到这个乱码“ \330\370\277_\377 ”。谁能告诉我我做错了什么?任何帮助将不胜感激。
非常感谢!
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <stdint.h>
int main()
{
char line[81], filename[21];
int i;
FILE *inFile;
printf("\nPlease enter the name of a file: ");
gets(filename);
inFile = fopen(filename, "r");
if(inFile == NULL)
{
printf("\nThe file %s was not successfully opened.", filename);
printf("\nPlease check that the specified file exists.");
getchar();
exit(1);
}
while (fgets(line, 81, inFile) != NULL)
printf("\n%s\n", line);
for (i = 0; line[i]; ++i) {
line[i] = toupper(line[i]);
}
printf("\nPrinted in UPPER case: \n\n");
rewind(inFile);
printf("\n%s", line);
getchar();
}