Katie Melosto
Katie Melosto

Reputation: 1177

expected parameter declarator error using fread() in C

I'm using fread() to read a binary file. I want to read in into as an unsigned short int. I keep getting this error expected parameter declarator for the following code:

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).

Upvotes: 0

Views: 318

Answers (1)

anastaciu
anastaciu

Reputation: 23832

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.

The binary_file parameter is not being used, maybe this is what you intended to use.

Placing the return type before the function as you are using it is also not correct, that is for declaration or definition.

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

Upvotes: 1

Related Questions