rewind function in c

rewind() function in c

Declaration:
void rewind(FILE *fptr);

This rewind(FILE *fptr) functionis used to move the file position indicator to the beginning of the file, this function rewind() is usefull when we open a file for update.

The rewind(fptr) is equivalent to fseek(fptr,0L,0); and clearerr(fptr);

/* program to understand the use of rewind() */
#include<stdio.h>
#include<stdlib.h>
int
main()
{
FILE *fptr;
fptr=fopen("stu","rb+");
if (fptr==NULL)
{
printf("Error when open file \n" );
exit (1);
}
printf("position indicator--%ld\n", ftell(fptr));
fseek(fptr,0,3);
printf("position indicator--%ld \n", ftell(fptr));
rewind(fptr);
printf("position indicator-- %ld \n", ftell(fptr));
fclose(fptr);
return 0;
}

Error when open file