简体   繁体   English

不兼容的指针类型,将'char *'传递给'FILE *'类型的参数(又名'struct__sFILE *')

[英]incompatible pointer types passing 'char*' to parameter of type 'FILE*'(aka 'struct__sFILE*')

I have a frustrating problem. 我有一个令人沮丧的问题。 I am getting the following error: 我收到以下错误:

incompatible pointer types passing 'char*' to parameter of type FILE*'(aka 'struct__sFILE*')". 不兼容的指针类型,将'char *'传递给FILE *'(aka'struct__sFILE *')类型的参数。

Anyone know how I would fix this problem? 有人知道我将如何解决此问题?

void load_myFile(char my_file_name[]) {
    if(my_file_name != NULL) {
        int op_code, L_code, M_code, i = 0;
        while(my_file_name != NULL) {
            fscanf(my_file_name, "%d", &op_code);

            if(i > MAX_CODE_LENGTH) {
                printf("Program is longer than MAX_CODE_LENGTH\n");
                exit(ERROR_PROG_TOO_LONG);
            }
            fscanf(my_file_name, "%d", &L_code);
            fscanf(my_file_name, "%d", &M_code);

            code[i].op = op_code;
            code[i].l = L_code;
            code[i].m = M_code;
            i++;
        }
        code_size = i;
    }

According to your declaration, my_file_name is a string of char, not a pointer to FILE. 根据您的声明,my_file_name是一个字符串,不是指向FILE的指针。 While function fscanf requires a pointer to FILE. 而函数fscanf需要一个指向FILE的指针。 Therefore you got that kind of error. 因此,您会遇到这种错误。

If you want it to be a string, use sscanf instead of fscanf to extract data. 如果希望它是字符串,请使用sscanf而不是fscanf来提取数据。 Otherwise, declare a FILE pointer, open a file and read from it. 否则,声明一个FILE指针,打开一个文件并从中读取。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 警告:不兼容的指针类型将“char *”传递给“FILE *”类型的参数(又名“struct __sFILE *”) - warning: incompatible pointer types passing 'char *' to parameter of type 'FILE *' (aka 'struct __sFILE *') 如何修复将'char [16]'传递给'FILE *'类型的参数(又名'struct __sFILE *')的不兼容指针类型[-Wincompatible-pointer-types] - how to fix incompatible pointer types passing 'char [16]' to parameter of type 'FILE *' (aka 'struct __sFILE *') [-Wincompatible-pointer-types] 不兼容的指针类型,将“ char(*)[128]”传递给类型为“ char **”的参数 - incompatible pointer types passing 'char (*)[128]' to parameter of type 'char **' 不兼容的指针类型将“char (*)[3]”传递给“const char *”类型的参数 - incompatible pointer types passing 'char (*)[3]' to parameter of type 'const char * 不兼容的指针类型将'char *(char *)'传递给类型'VALUE(*)()'的参数 - incompatible pointer types passing 'char *(char *)' to parameter of type 'VALUE (*)()' 将 char** 传递给 void** function 参数时与指针类型不兼容的指针类型警告 - Incompatible pointer type warning with pointer-to-pointer types when passing char** to void** function parameter C:将“char (*)”传递给“char (*)[5]”类型参数的不兼容指针类型,但程序运行正常 - C: incompatible pointer types passing 'char (*)' to parameter of type 'char (*)[5]', but program works fine 将“void *(struct thread_args *)”传递给“void * _Nullable (* _Nonnull)(void * _Nullable)”类型参数的不兼容指针类型 - Incompatible pointer types passing 'void *(struct thread_args *)' to parameter of type 'void * _Nullable (* _Nonnull)(void * _Nullable)' 指针转换不兼容的整数,将“ char”传递给类型为“ const char *”的参数 - Incompatible integer to pointer conversion passing 'char' to parameter of type 'const char *' 指针转换不兼容的整数,将“ int”传递给类型为“ const char *”的参数 - Incompatible integer to pointer conversion passing 'int' to parameter of type 'const char *'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM