c - 打开文件并使用 toupper

标签 c

我正在为学校做一项作业,需要我打开一个文件名,然后重新打印它,使所有内容都大写。当尝试编译时,我遇到了多个错误,从“函数不接受参数”到“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;
}

最佳答案

  1. 改变

    char *fileName[20];

   char fileName[20];
  • 了解 proper use of fgets

  • 同时阅读 toupper 的手册页

  • ...

    事实上,在使用某些东西时,最好阅读手册,而不是希望得到最好的结果

    关于c - 打开文件并使用 toupper,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37236693/

    相关文章:

    C - 使用递归打印链表

    c - 如何在C中打印用户输入的数字的位数?

    c - Lex/flex 程序,用于计算 id、语句、关键字、运算符等

    c - 返回值的函数定义中的缺失 - 什么类型的错误?

    c++ - 如何使用 c++/c 从 Windows 命令行一次运行多个命令?

    c - 如何将视频容器中的十六进制值转换为 UTC 时间戳?

    c++ - 在 typedef 上使用 sizeof 而不是局部变量

    c - FFmpeg:Jpeg 文件到 AVFrame

    c - 如何以编程方式确定驱动器的空间/大小?在 LInux 和 Windows 中

    c - 为什么 __last__ 元素需要 c struct 填充