470,815 Members | 1,264 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,815 developers. It's quick & easy.

text and binary streams

In K & R ANSI C book(2nd Edition), in page 241, the following lines
are mentioned.

"The library supports text streams and binary streams, although on
some systems, notably UNIX, these are identical."

Here I am unable to understand what is meant by saying "the streams
are identical" ?

Kindly clarify. If possible give an example so that I can understand.

Thanks
V.Subramanian
Aug 23 '08 #1
2 1471
In article <b4**********************************@j1g2000prb.g ooglegroups.com>,
su**************@yahoo.com, India <su**************@yahoo.comwrote:
>In K & R ANSI C book(2nd Edition), in page 241, the following lines
are mentioned.

"The library supports text streams and binary streams, although on
some systems, notably UNIX, these are identical."

Here I am unable to understand what is meant by saying "the streams
are identical" ?
The best-known example is the difference in how line-endings are
represented in unix and msdos-derived systems. Unix uses a single
linefeed character at the end of each line. Windows uses the
two-character sequence carriage-return-linefeed.

C specifies that when reading text files you get a linefeed at the end
of each line, so on MS Windows the system has to translate cr-lf to lf
in text mode (and the reverse for writing), but not in binary mode.
On unix the file representation is already the same as C's, so no
translation is needed in text mode, and it works just the same way as
binary mode.

-- Richard
--
Please remember to mention me / in tapes you leave behind.
Aug 23 '08 #2
On Sun, 24 Aug 2008 03:36:46 UTC, Jack Klein <ja*******@spamcop.net>
wrote:
>
Which only goes to prove that if there were "\n\r" systems in the
early 80's, they weren't used in the sort of places that bought our
products.
I don't think that ever a system using '\n\r' would exist. Because
based on the very old times before even CP/M was existent there were
existent priters (e.g. on TTY) who used '\r' to move the print head to
begin of line only and '\n' only to move the paper try a line up.
Whereas using '\n' followed by '\r' and then the next letter printing
out that letter on the fly where the carridge was underway to begin of
line, whereas the sequence '\r\n' caused the print unit to wait until
the carridge had reached t
he begin of line position before the '\n' was carried out.

A sample:

You had used
fprintf("----------------------------------------------------\n\r");
fprintf("monkey\r/n");
The printout looked like
-
------------------------------------------------------------
ey k on m
instead of
------------------------------------------------------------
monkey

as it should. So it was essential to print out '\r' before '\n' to
give the print unit time to let the carridge return, and then paper
try was holding the unit until it was finished the paper one line
forward, because it had to reead its punched paper stripe that
signaled the step wide a line and a page was high.

--
Tschau/Bye
Herbert

Visit http://www.ecomstation.de the home of german eComStation
eComStation 1.2R Deutsch ist da!
Aug 24 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Tron Thomas | last post: by
8 posts views Thread by Dave Moore | last post: by
8 posts views Thread by Yeow | last post: by
26 posts views Thread by Patient Guy | last post: by
8 posts views Thread by FUGATO | last post: by
7 posts views Thread by Hallvard B Furuseth | last post: by
6 posts views Thread by Alexander Vasilevsky | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.