C library functions - rewind ()
C standard library - <stdio.h>
description
C library functionsvoid rewind (FILE * stream) at the beginning of the file location set for a given flow streamfiles.
statement
Here is the rewind () function's declaration.
void rewind(FILE *stream)
parameter
- stream - This is a pointer to FILE pointer to an object, the object identifier FILE flow.
return value
This function does not return a value.
Examples
The following example demonstrates rewind () function is used.
#include <stdio.h> int main() { char str[] = "This is w3cschool.cc"; FILE *fp; int ch; /* 首先让我们在文件中写入一些内容 */ fp = fopen( "file.txt" , "w" ); fwrite(str , 1 , sizeof(str) , fp ); fclose(fp); fp = fopen( "file.txt" , "r" ); while(1) { ch = fgetc(fp); if( feof(fp) ) { break ; } printf("%c", ch); } rewind(fp); printf("\n"); while(1) { ch = fgetc(fp); if( feof(fp) ) { break ; } printf("%c", ch); } fclose(fp); return(0); }
Suppose we have a text filefile.txt, which reads as follows:
This is w3cschool.cc
Let's compile and run the above program, which will result in the following:
This is w3cschool.cc This is w3cschool.cc