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.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- fseek() in C/C++ with example
- Sorting strings from the text file
- Brief Overview & Comparison of Object-Oriented Programming from C to Java
- Relational Database from CSV Files in C
- What is Cloudflare?
- Bug Tracking System
- C Program to sort rows of the Matrix
- Advantages and Disadvantages of Array in C
- Types of C files after its compilation
- Food Ordering System in C
- Difference between sizeof(int *) and sizeof(int) in C/C++
- Examination Management System in C
- Difference between Static and Dynamic Memory Allocation in C
- 10 Web Development and Web Design Facts That You Should Know