[ First ]  [ Previous ]  [ Next ]  [ Last ]  [ Manuals ]


rewind

Reset the file position indicator to the beginning of the file.

Compatibility:

This function is compatible with the following targets:

ANSI

BeOS

EMB/RTOS

Mac OS

Palm OS

Win32


Prototype:
#include <stdio.h>
void rewind(FILE *stream);
Parameters:

Parameters for this facility are:

stream  
FILE *  
A pointer to a FILE stream  

Remarks:

The rewind() function sets the file indicator position of stream such that the next write or read operation will be from the beginning of the file. It also undoes any previous call to ungetc() and clears stream's end-of-file and error status.


NOTE

On embedded/ RTOS systems this function only is implemented for stdin, stdout and stderr files.
See Also:

"fseek"

"fsetpos"

Example of rewind() usage.:
#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