[英]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.