aa*****@gmail.com writes:
http://www.c-faq.com/stdio/textvsbinary.html
it is written as follows
Furthermore, for analogous reasons, the fseek and ftell functions do
not necessarily deal in pure byte offsets from the beginning of the
file.
can anybody give examples/explanations for this ??
what exactly is this pure byte offset value ??
Does it mean that offset values are those which can be represented by
a string of 8 bits??
No, it refers to an offset value that represents a simple count of
bytes, counted from the beginning of the file.
On some systems, all files are represented as sequences of bytes, with
no additional structure imposed by the operating system. On such a
system, the simplest way to represent a position within a file (the
value returned by ftell() and used by fseek() is just a count of the
number of bytes between the beginning of the file and the specified
position.
For text files, the way an end-of-line is represented in the file can
complicate things. For example, each end-of-line might be represented
as a 2-character sequence, but getchar() must still return a single
'\n' character when it reads this sequence. This means that the
number of bytes that have been read by getchar() might not be the same
as a simple byte offset from the beginning of the file.
Examples:
Unix-like systems use a single ASCII LF character to indicate the end
of a line, and there's no real difference in behavior between text
files and binary files. fseek() and ftell() use a simple count of
bytes to indicate a positoin within a file, either text or binary.
Windows systems use a pair of characters, ASCII CR followed by ASCII
LF, to indicate the end of a line. If you read such a file in binary
mode, you'll see the CR and the LF characters individually (as '\r'
and '\n'). If you read the file in text mode, you'll only see a
single '\n' character. I *think* that fseek and ftell still use a
simple count of bytes to represent an offset within a file, but this
count doesn't necessarily match the number of characters that can be
read from the file in text mode.
--
Keith Thompson (The_Other_Keith)
ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.