In C, fseek() should be preferred over rewind().
Note the following text C99 standard:
The rewind function sets the file position indicator for the stream pointed to by stream to the beginning of the file. It is equivalent to
except that the error indicator for the stream is also cleared.
This following code example sets the file position indicator of an input stream back to the beginning using rewind(). But there is no way to check whether the rewind() was successful.
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);
This article is contributed by Rahul Gupta. Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details
- fseek() in C/C++ with example
- Difference Between C Language and LISP Language
- Pointer Arithmetics in C with Examples
- Difference between GCC and G++
- Difference and Similarities between PHP and C
- Format specifiers in different Programming Languages
- C program to find square root of a given number
- C program to print odd line contents of a File followed by even line content
- Getting System and Process Information Using C Programming and Shell in Linux
- Program to calculate Electricity Bill
- Program to print half Diamond star pattern
- C/C++ program for calling main() in main()
- Interesting and Cool Tricks in Java
- Print all possible combinations of the string by replacing '$' with any other digit from the string