Get a stream's current file position indicator value.
Compatibility:This function is compatible with the following targets:
|
|
#include <stdio.h>
int fgetpos(FILE *stream, fpos_t *pos);Parameters:
Parameters for this facility are:
NOTE
fgetpos() returns zero when successful and returns a nonzero value when it fails.
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
FILE *f;
fpos_t pos;
char filename[80], buf[80];
// get a filename from the user
printf("Enter a filename to read.\n");
gets(filename);
// open the file for input
if (( f = fopen(filename, "r")) == NULL) {
printf("Can't open %s.\n", filename);
exit(1);
}
printf("Reading each line twice.\n");
// get the initial file position indicator value
// (which is at the beginning of the file)
fgetpos(f, &pos);
// read each line until end-of-file is reached
while (fgets(buf, 80, f) != NULL) {
printf("Once: %s", buf);
// move to the beginning of the line to read it again
fsetpos(f, &pos);
fgets(buf, 80, f);
printf("Twice: %s", buf);
// get the file position of the next line
fgetpos(f, &pos);
}
// close the file
fclose(f);
return 0;
}
Output:
Enter a filename to read.
myfoo
Reading each line twice.
Once: chair table chest
Twice: chair table chest
Once: desk raccoon
Twice: desk raccoon */
[ 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