Set the file pointer to the beginning of a stream: how to use rewind : File Pointer « File « C / ANSI-C






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

1.Reset file position indicator to start of the file
2. Return the current position in a stream: how to use ftell
3.Reposition file pointer to a saved location: how to use fsetpos