![]() Chapter Contents |
![]() Previous |
![]() Next |
| rewind |
| Portability: | ISO/ANSI C conforming, UNIX compatible |
| SYNOPSIS | |
| DESCRIPTION | |
| RETURN VALUE | |
| EXAMPLE | |
| RELATED FUNCTIONS | |
| SEE ALSO |
| SYNOPSIS |
#include <stdio.h> void rewind(FILE *f);
| DESCRIPTION |
rewind
positions the stream associated with the
FILE
object addressed by
f
to its first
character. It also resets the error flag for the stream if it is set.
| RETURN VALUE |
rewind
has no return value.
| EXAMPLE |
#include <stdio.h>
#define RECLEN 80
FILE *f; /* file to be searched */
char *search(int); /* prototype of the search function */
main()
{
int n ; /* The record number to be found */
/* points to the address of a copy of */
/* the returned record. */
char *addr;
/* Ask the user for the number of the record to */
/* be found. */
puts("Which record do you want to read?");
scanf("%d", &n);
addr = search(n);
printf("The record is %s\n", *addr);
}
/* performs the search and rewind of the file f */
char *search(int n){
char *record; /* points to a copy of the record */
int i;
while (!feof(f)) {
/* Read the records until the nth one is found. */
for (i=0; i <= n; i++)
afread(record, RECLEN, 1, f);
}
/* Reposition the stream to the top of f. */
rewind(f);
/* Return the address of the copy of the record. */
return record;
}
| RELATED FUNCTIONS |
| SEE ALSO |
![]() Chapter Contents |
![]() Previous |
![]() Next |
![]() Top of Page |
Copyright © 2001 by SAS Institute Inc., Cary, NC, USA. All rights reserved.