PC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11Crashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minuteCall rewind(stream) to move a C file stream back to the beginning before reading it again. The function also clears the stream’s end-of-file and error indicators, but it returns no value—so you cannot check success with a return-value test.
What rewind() does
Declare it by including <stdio.h>. Its signature is void rewind(FILE *stream);. It moves the file-position indicator for stream to the beginning of the file and clears the end-of-file and error indicators. Any effects from earlier ungetc() calls are discarded. The C library reference documents these semantics.
As an Amazon Associate I earn from qualifying purchases.
Because its return type is void, rewind() does not report success or failure through a return value.
Free tools Windows power users keep installed
One-click scans. No signup required.
How to read a file from the beginning again
Keep the stream open, finish the first pass, rewind it, then perform the next read. For example:
#1 Best Overall
#include <stdio.h>
int main(void)
{
FILE *stream = fopen("input.txt", "r");
if (stream == NULL) {
perror("fopen");
return 1;
}
/* Read or process the stream here. */
rewind(stream);
/* Read or process the stream again from the beginning. */
if (fclose(stream) == EOF) {
perror("fclose");
return 1;
}
return 0;
}
The comments mark where the program’s actual reading logic belongs. The example demonstrates the intended sequence; it does not establish that repositioning succeeds for every stream or platform situation.
rewind() vs. fseek()
Both rewind(stream) and fseek(stream, 0L, SEEK_SET) can position a stream at its beginning. Choose based on whether you need a fixed destination or more control over positioning and status reporting.
| Function | Positioning | Return value | Indicator effects |
|---|---|---|---|
rewind(stream) |
Beginning of the file only | None (void) |
Clears the end-of-file and error indicators; discards effects from prior ungetc() calls. C library reference |
fseek(stream, offset, whence) |
Chosen offset relative to SEEK_SET (start), SEEK_CUR (current position), or SEEK_END (end) |
Reports status | Unlike rewind(), does not provide its additional error-indicator clearing. POSIX.1-2017 |
Use rewind() when the only destination you need is the start. Use fseek() when you need another position or want to inspect a function return status. The C library reference for fseek() describes its offset and origin arguments.
Error detection and portability
Do not write if (rewind(stream) != 0): there is no return value to test. POSIX.1-2017 says that an application wishing to detect errors may clear errno before calling rewind(), then treat a nonzero errno afterward as an indication of an error. This is POSIX guidance, not a return-value check, and should not be presented as a portable C success test. See the POSIX.1-2017 specification.
Quick Recap
Best Value
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




