rewind() in C
The rewind() function is used to bring the file pointer to the beginning of the file. It can be used in place of fseek() when you want the file pointer at the start.
Syntax of rewind()
rewind (file_pointer);
Example
C
// C program to illustrate the use of rewind #include <stdio.h> int main() { FILE * fptr; fptr = fopen ( "file.txt" , "w+" ); fprintf (fptr, "Geeks for Geeks\n" ); // using rewind() rewind (fptr); // reading from file char buf[50]; fscanf (fptr, "%[^\n]s" , buf); printf ( "%s" , buf); return 0; } |
Geeks for Geeks
Basics of File Handling in C
File handing in C is the process in which we create, open, read, write, and close operations on a file. C language provides different functions such as fopen(), fwrite(), fread(), fseek(), fprintf(), etc. to perform input, output, and many different C file operations in our program.