Question 12.25

What's the difference between fgetpos/fsetpos and ftell/fseek?
What are fgetpos and fsetpos good for?


fgetpos and fsetpos use a special typedef, fpos_t, for representing offsets (positions) in a file. The type behind this typedef, if chosen appropriately, can represent arbitrarily large offsets, allowing fgetpos and fsetpos to be used with arbitrarily huge files. ftell and fseek, on the other hand, use long int, and are therefore limited to offsets which can be represented in a long int. See also question 1.4.

References: K&R2 Sec. B1.6 p. 248
ANSI Sec. 4.9.1, Secs. 4.9.9.1,4.9.9.3
ISO Sec. 7.9.1, Secs. 7.9.9.1,7.9.9.3
H&S Sec. 15.5 p. 252


Read sequentially: prev next up top


This page by Steve Summit // Copyright 1995 // mail feedback