Reset the file position indicator to the beginning of the file.
Compatibility:This function is compatible with the following targets:
|
|
#include <stdio.h>
void rewind(FILE *stream);Parameters:
Parameters for this facility are:
NOTE
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
FILE *f;
char filename[80], buf[80];
// get a filename from the user
printf("Enter a filename to read.\n");
gets(filename);
// open a file for input
if (( f = fopen(filename, "r")) == NULL) {
printf("Can't open %s.\n", filename);
exit(1);
}
printf("Reading first line twice.\n");
// move the file position indicator to the beginning
// of the file
rewind(f);
// read the first line
fgets(buf, 80, f);
printf("Once: %s\n", buf);
// move the file position indicator to the
//beginning of the file
rewind(f);
// read the first line again
fgets(buf, 80, f);
printf("Twice: %s\n", buf);
// close the file
fclose(f);
return 0;
}
Output:
Enter a filename to read.
itwerks
Reading first line twice.
Once: flying fish and quail eggs
Twice: flying fish and quail eggs
[ First ] [ Previous ] [ Next ] [ Last ] [ Manuals ]
Visit the Metrowerks website at: http://www.metrowerks.com
For assistance contact Metrowerks Technical Support at: cw_support@metrowerks.com
Copyright © 2000, Metrowerks Corp. All rights reserved.
Last updated: August 16, 2000