vim said:
hello everybody
Plz tell the differance between binary file and ascii
file...............
Well, that's really the wrong question.
The right question is: "what is the difference between a stream opened in
binary mode, and a stream opened in text mode?"
Let's deal with the easy one first. When you associate a binary stream with
a file, the data flows in from the file, through the stream, unmodified
(or, if you're writing, it flows out, through the stream, to the file,
unmodified). It's just a raw stream of bytes, to do with as you will.
Okay, now the hard one. When you associate a /text/ stream with a file, you
are assuming the convention that the data comprises zero or more lines,
where each line is composed of 0 or more bytes followed by a newline marker
of some kind.
The newline marker defined by C is '\n'.
On Unix, this agrees well with the marker actually used by longstanding
convention on that system.
On CP/M and derivatives (such as Q-DOS and that point-and-click adventure
game it spawned), the marker is '\r' and '\n', in that order.
On the Mac, it's just plain '\r'.
On the mainframe - well, you /really/ don't want to know.
All this is a bit of a nuisance, and it would be nice if we didn't have to
bother with such niceties when processing plain ol' text. And so, when you
are reading from a text stream, the standard library performs any necessary
conversions on incoming data, to force-map the newline marker into a nice
simple '\n'. And when you are writing to the stream, the standard library
looks for '\n' characters and replaces them with the byte or bytes used for
marking newlines on the particular system on which the program is running.
So, when you are writing your code, you can just pretend that the newline
marker is '\n', and - to all intents and purposes - so it is! So you don't
have to mess about with detecting whether you're running on a Mac or a mini
or a mainframe - you can just assume a '\n' delimiter and let the standard
library worry about the underlying representation.
If you don't /want/ the system to do this, open the file in binary mode. But
then managing the newline stuff all falls to you instead.