More less it's my first time working with files in C, having a hard time understanding fread, fwrite and all that jazz. So I was trying to copy the header of the file saved in input folder to another file, stored with the output pointer. I keep getting an error on line 47 about & read; "expected parameter declarator". Overall whatever I do to read the compiler screams at me. And Im not sure if fseek was necessary. Any advice?
fseek(input, HEADER_SIZE, SEEK_SET);
int read;
fread(&read, HEADER_SIZE, 1, input);
fseek(input, HEADER_SIZE, SEEK_SET);
for (int i = 0; i < HEADER_SIZE; i++)
{
uint8_t fwrite(read[i], sizeof(int), 1, output);
fseek(input, i++ ,SEEK_CUR);
}
The error "expected parameter declarator" on line 47 is because you're missing the address of the variable you want to write to. The
freadfunction expects a pointer to the memory location where the data should be read into. In your case, you should pass the address of the read variable to read:This will read
HEADER_SIZEbytes from the input file into thereadvariable.The
fseekfunction is used to seek to a specific position in a file. In your code, you're using it to seek to the beginning of the header after reading it into the read variable. This is necessary because you want to start writing the header to the output file at the beginning.