|
How to back up the file pointer
#include <stdio.h>
main ()
{
FILE * p = fopen ("c:\\1.txt", "r");
char cTemp;
printf ("% ld\n", ftell (p));
cTemp = fgetc (p);
printf ("% ld\t", ftell (p));
printf ("% c\n", cTemp);
cTemp = fgetc (p);
printf ("% ld\t", ftell (p));
printf ("% c\n", cTemp);
fseek (p, SEEK_CUR, -1L);
printf ("% ld\n", ftell (p));
while ((cTemp = fgetc (p))! = EOF)
{
printf ("% ld\t", ftell (p));
printf ("% c\n", cTemp);
}
getch ();
} |
|