我正在为学校做一项作业,需要我打开一个文件名,然后重新打印它,使所有内容都大写。当尝试编译时,我遇到了多个错误,从“函数不接受参数”到“char 与 int 类型不兼容”和“fileName 未声明的标识符”等等。我已经在互联网和我的 C 编程书籍上搜索了几个小时,但我只是不明白。任何帮助是极大的赞赏。
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
int main()
{
FILE *inFile;
char *fileName[20];
printf("Enter a file name: ");
fgets(*fileName);
inFile = fopen_s(*fileName, "r");
if (inFile == NULL)
{
printf("\nThe file %s was not successfully opened.", *fileName);
printf("\nPlease check that the file currently exists.\n");
exit(1);
}
printf("\nThe file has been successfully opened for reading.\n");
printf("\n%fileName", toupper(*fileName));
return 0;
}
最佳答案
改变
char *fileName[20];
至
char fileName[20];
同时阅读
toupper
的手册页
...
事实上,在使用某些东西时,最好阅读手册,而不是希望得到最好的结果
关于c - 打开文件并使用 toupper,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37236693/