简体   繁体   English

在 C 中使用 fread() 的预期参数声明错误

[英]expected parameter declarator error using fread() in C

I'm using fread() to read a binary file.我正在使用 fread() 来读取二进制文件。 I want to read in into as an unsigned short int.我想读入一个无符号的短整数。 I keep getting this error expected parameter declarator for the following code:我不断收到以下代码的此错误expected parameter declarator符:

int analyzeFile (FILE* binary_file , mem_location** memory)
{

    unsigned short int row;
    size_t fread (&row, sizeof(unsigned short int), 1, FILE* my_obj_file);
    
    fclose(my_obj_file);
    return 0 ;
}

I believe I'm misusing the memory address of row and the sizeof(unsigned short int).我相信我滥用了row的 memory 地址和 sizeof(unsigned short int)。

FILE* my_obj_file

if it's supposed to be a cast it must be如果它应该是一个演员,它必须是

(FILE*) my_obj_file

It's hard to know because this variable is not declared in the scope of the function, either way it's not a valid parameter.很难知道,因为这个变量没有在 function 的 scope 中声明,无论哪种方式它都不是有效参数。

The binary_file parameter is not being used, maybe this is what you intended to use.未使用binary_file参数,也许这是您打算使用的。

Placing the return type before the function as you are using it is also not correct, that is for declaration or definition.在您使用它时将返回类型放在 function 之前也是不正确的,即用于声明或定义。

What you might want is:你可能想要的是:

size_t size = fread (&row, sizeof(unsigned short int), 1, binary_file); //or my_obj_file
            ^                                            ^
     assign return value                            no type used

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM