HP C/iX Library Reference Manual (30026-90004)

294 Chapter5
HP C/iX Library Function Descriptions
rewind
rewind
Sets the file position indicator for a stream to the beginning of the file.
Syntax
#include <stdio.h>
void rewind (FILE *
stream
);
Parameters
stream
A pointer to an open stream.
Return Values
None.
Description
The rewind function sets the file position indicator for the specified stream to the
beginning of the file.
NOTE
If you have a stream open for both reading and writing, a read operation
cannot be followed by a write operation without one of the following occurring
first: a rewind(),anfseek(), or a read operation that encounters end-of-file.
Similarly, a write operation cannot be followed by a read operation unless a
rewind() or fseek() is performed.
Example
Suppose you sometimes wish to use a password on a data file accessed by an application
program. This password is to be optionally stored in encrypted form on the first line of the
file. The line is recognized as a password line if the first two characters are "*P". If the file
has no password line, access to the file is unrestricted. If a password line is found, the
program prompts for the password before permitting access. The following code looks for a
password line:
#include <stdio.h>
main(argc, argv)
int argc;
char *argv[ ];
{
FILE *pswd;
char line[256];
if(argc != 2) {
fprintf(stderr, "Usage: getpswd file\n");
exit(1);