curr_char
is a char pointer.
In that case,
curr_char = fgetc(arch_file);
is wrong. You're implicitly converting the int
returned by fgetc
to a char*
, and then in fwrite
, that value is interpreted as an address, from which the sizeof(char*)
bytes are tried to be read and written to the file.
If curr_char
points to memory allocated for a char
,
*curr_char = fgetc(arch_file);
fwrite(curr_char, 1, sizeof *curr_char, file_to_write);
would be closer to correctness. But fgetc
returns an int
and not a char
for a reason, it may fail, in which case it returns EOF
. So you should have
int chr = fgetc(arch_file);
if (chr == EOF) {
break; // exit perhaps?
}
char c = chr; // valid character, convert to `char` for writing
fwrite(&c, 1, sizeof c, file_to_write);
to react to file reading errors.