473,322 Members | 1,504 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,322 software developers and data experts.

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 1605
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Tron Thomas | last post by:
What does binary mode for an ofstream object do anyway? Despite which mode the stream uses, operator << writes numeric value as their ASCII representation. I read on the Internet that it is...
8
by: Dave Moore | last post by:
I realize this is a somewhat platform specific question, but I think it is still of general enough interest to ask it here ... if I am wrong I guess I will find out 8*). As we all know, DOS uses...
14
by: nic977 | last post by:
I am asked to write a simple program to displays the last n lines from a given text file. But I have no ideas how C defines a "line" in a text file. How does it tell if it is the end of the line,...
8
by: Yeow | last post by:
hello, i was trying to use the fread function on SunOS and ran into some trouble. i made a simple test as follows: i'm trying to read in a binary file (generated from a fortran code) that...
36
by: Wei Su | last post by:
Hi, I have a text file abc.txt and it looks like: 12 34 56 23 45 56 33 56 78 ... .. .. ... .. .. I want to get how many rows totally in the text file, how to do this? Thanks.
26
by: Patient Guy | last post by:
Has anyone written code that successfully manipulates binary file data using Javascript? It might---and in the case of doing I/O, will---make use of browser- specific functions (ActiveX/COM with...
8
by: FUGATO | last post by:
I need to help in my assignment. I need to wrap a text with the following indications: 1.If you have reached the end of the line (number of characters on this line >= 40) AND you have reached the...
7
by: Hallvard B Furuseth | last post by:
I'm trying to clean up a program which does arithmetic on text file positions, and also reads text files in binary mode. I can't easily get rid of it all, so I'm wondering which of the following...
6
by: Alexander Vasilevsky | last post by:
How do I know whether the file is text or binary? http://www.alvas.net - Audio tools for C# and VB.Net developers + Christmas discount
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
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: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
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
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
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

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.