I 've been searching all over the internet for a way to read a file twice but all the results i could find were about c++ or were talking about a rewind() function which doesn't work for me. so any suggestions of how i can reset the *fp?
I 've been searching all over the internet for a way to read a file twice but all the results i could find were about c++ or were talking about a rewind() function which doesn't work for me. so any suggestions of how i can reset the *fp?
rewind() was made for that purpose!
If for some reason you don't like it, you can always close, and then reopen the file, same as the first time.
fclose(fp), then fopen, just like before.
A third option would be to use fseek(), but that's no better than rewind().
Given that both fseek() and rewind() work only on opened files... No, there's no need to open the file again...
> A third option would be to use fseek(), but that's no better than rewind().
Except that rewind() will also clear the eof condition, if you read to the end of the file.
rewind(3): reposition stream - Linux man page
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.