display pointer position of file
hi every kindly tell me how to display pointer position for eg
fpos_t pos;
(fgetpos(fp, &pos) how to d开发者_运维百科isply pos value
thanks
To do this portably you're not supposed to try and display that pos value. Try using ftell() instead.
long pos;
pos = ftell(fp);
printf("pos is %ld bytes\n", pos);
You can't. An fpos_t contains more than the offset: it has information to reset correctly the handling of character sets having a shift state. ftell() gives you an offset (but pay attention, its range can be limited to less that the possible file size).
In some Unix systems fpos_t
is equivalent to off_t
or long int
, but in other systems, it might have a different internal representation.
pos_t position;
fgetpos(stream, &position);
...
fsetpos(stream, &position);
printf("offset: %ld\n", position.__pos);
^^^ ^^^^^
With a long
integer data type it works fine, but I repeat that the internal representation of fpos_t
varies from system to system.
精彩评论