The rewind function sets the file position indicator for the stream pointed to by stream to the beginning of the file.
Example
int main()
{
FILE *fp = fopen("test", "r");
if ( fp == NULL ) {
/* Handle open error */
}
/* Do some processing with file*/
...
rewind(fp); /* This will set the indicator at the start of the file again */
...
}
However its not safe to user rewind as there is no way to check if rewind is successful or not. In the above code, fseek() can be used instead of rewind() to see if the operation succeeded. Following lines of code can be used in place of rewind(fp);
if ( fseek(fp, 0L, SEEK_SET) != 0 ) {
/* Handle repositioning error */
}
Credit: https://www.securecoding.cert.org/confluence/display/seccode/FIO07-C.+Prefer+fseek%28%29+to+rewind%28%29