473,320 Members | 2,109 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

textvsbinary

Hi all

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??

Apr 21 '06 #1
2 1371
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.
Apr 21 '06 #2
aa*****@gmail.com wrote:
Hi all

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 ??
In DOS/Windows text files each end of line will be marked by 2
characters, CRLF, but when you read the file in text mode you will just
see a single newline character. So given the text file:
a
b
you actually have 6 characters, a, carriage return, new line, b,
carriage return, new line. When read in text mode you would see 4
characters, "a/nb/n". So the return values for ftell could be:
a = 0
first /n = 1
b = 3
first /n = 4
Or equally sensibly:
a = 0
first /n = 2
b = 3
first /n = 5
Neither of these corresponds to what you would expect when reading the file.

Alternatively, the system could do clever things to make it look as you
would expect (I seem to recall Jacob has opinions on this and knows of
implementations that do it) so you would get:
a = 0
first /n = 1
b = 2
first /n = 3

Obviously, whatever definition you use for "byte offset", either based
on the number of bytes you would have to read, or the number of bytes in
the real file, at *least* one of the above cannot be a simple byte offset.
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 means the number of bytes you would have to read to get to that
position from the start of the file.
--
Flash Gordon, living in interesting times.
Web site - http://home.flash-gordon.me.uk/
comp.lang.c posting guidelines and intro:
http://clc-wiki.net/wiki/Intro_to_clc
Apr 21 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Claude Yih | last post by:
Hi, everyone. I noticed an interesting thing about fread() this afternoon. Well, I can't see why so I post this message in the hope of getting some explanation. Please help me. I wrote the...
25
by: subramanian100in | last post by:
Consider the following program: #include <stdio.h> #include <stdlib.h> int main(int argc, char *argv) { if (argc != 2) { printf("Usage: <program-name<text-file>\n");
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.