I am doing pset4 recover.c and have a bit of confusion..

Does this move the pointer?

while(fread(buffer,1,512,card) == 512){
   rewind(); // do I need to rewind? or just write what's in buffer?

1 Answer 1


When you do an fread, whether it is in a while loop statement or anywhere else, it will execute the read and will most definitely move the file pointer. The pointer will be repositioned to the first byte following the read.

For example, if the pointer is at byte 0, or the start of the file, and fread reads 3 bytes, it will read bytes 0, 1 and 2, and will position the pointer at byte 3. If the pointer were at byte 1000 and 3 bytes are read, the pointer will be at byte 1003 after the read.

Whether you need to rewind or move it somewhere else is entirely dependent on what you want to do next and has little to do wit the read, other than the read has moved the pointer as described above.

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .