rewind( ) function in C is used to move the file position pointer to the beginning of the file.
Through this article we will be going to discuss rewind( ) function of C in detail in which we will cover following topics.
- rewind( ) function in c
- header file for rewind( ) function in c
- return value of rewind( ) function in c
- rewind( ) function in c syntax
- rewind( ) function in c program
rewind( ) function in C
The rewind( ) function is nothing but, it is a standard library function of C and it also called file handling function which is basically used to move or in other words we can say that to bring the file position pointer to the beginning of the file where fptr is a pointer of file type,this function rewind( ) is very useful when we open a file for update.
Header file for rewind( ) function in C
This file function is define in <stdio.h> which is stand for standard input-output header file.
Return value of rewind( ) function in C
rewind( ) function return zero on success and if error occur than it returns non zero.
Syntax of rewind( ) function in C
rewind(FILE *pointer):
Example of rewind( ) function in C
#include<stdio.h>
#include<stdlib.h>
int main()
{
FILE *fp;
fp=fopen("stu.dat","rb+");
printf("Error in opening file\n");
exit(1);
printf("position pointer:ld\n",ftell(fp));
fseek(fp,0,2);
printf("position pointer:%ld\n",ftell(fp));
rewind(fp);
printf("Position pointer:%ld\n",ftell(fp));
fclose(fp);
return 0;
}
____________________________________
Conclusion:
rewind function is basically used to move position of the file pointer in the stream.
