I just have a conceptual question for how fread and fseek works in the context of the pset4's recover assignment. Initially when I was trying to write my program for this assignment, I was using fseek to iterate through the next 512 block of Bytes after every iteration of the while loop. I was using the following code
FILE *memory_file = fopen(argv, "r"); int i = 0; fseek(memory_file, (512 * i), SEEK_SET); i++; fread(BYTES, 1, 512, memory_file);
However, for some reason this wasn't working. Would using fseek in this contxt be wrong?
Then I changed the code by removing the fseek call and I started simply reading 512 Bytes from the memory_file and writing it into a new file that I have opened up and the assignment worked and got full marks.
Based on the above, it appears as though fread reads the next 512 bytes from where it is currently located in the file and not always from the start of the file. So for example in the 2nd iteration of the while loop, fread will read 512 bytes from the memory_file starting from Bytes #513 to Bytes #1024. Can you confirm if this is indeed how fread behaves?