I’m trying to read a file byte by byte and write it to another file. I have this code:
if((file_to_write = fopen(file_to_read, "ab+")) != NULL){
for(i=0; i<int_file_size; i++){
curr_char = fgetc(arch_file);
fwrite(curr_char, 1, sizeof(curr_char), file_to_write);
}
}
where int_file_size is the amount of bytes I want to read, arch_file is the file I’m reading from, and curr_char is a char pointer.
However this doesn’t work. I get Segmentation fault (core dumped) error on the first iteration in the loop. I’m pretty sure there is something wrong with my fwrite() statement. Any help would be appreciated.
You should pass the address of
curr_char, not thecurr_charitself: