Set the file pointer to the beginning of a stream: how to use rewind
#include <stdio.h>
int main ()
{
int n;
FILE *file;
char buffer[27];
file = fopen ("my.txt", "w+");
for ( n='A' ; n<='Z' ; n++)
fputc ( n, file);
rewind ( file );
fread (buffer, 1, 26, file);
fclose ( file );
buffer[26] = '\0';
puts ( buffer );
return 0;
}
Related examples in the same category