473,882 Members | 1,576 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

differance between binary file and ascii file

vim
hello everybody
Plz tell the differance between binary file and ascii
file........... ....
Thanks
in advance
vim

May 13 '06
68 5291
"P.J. Plauger" wrote:
"S.Tobias" <si***@FamOuS.B edBuG.pAlS.INVA LID> wrote in message
.... snip ...
Why is there the text mode in the first place? All operations valid
for text streams seem to be valid for binary ones, too. Text streams
are more difficult to handle (eg. you can't calculate offsets, there's
some extra undefinededness ). Apart from system compatibility, is there
any advantage to opening files in text mode?


System compatibility is a damned important reason. Every system has its
own convention for representing text files, as created by text editors
and consumed by other text-processing programs. If that convention doesn't
match the C convention -- zero or more lines of arbitrary length, each
terminated by a newline -- somebody has to do some mapping. Whitesmiths,
Ltd. introduced the text/binary dichotomy in 1978 when porting C to
dozens of non-Unix systems, and other companies did much the same thing
in the coming years. It was a slam dunk to put it in the draft C Standard
begun in 1983.

If you try to live with just binary mode, then every program either has
to map text files for itself or tolerate a broad assortment of rules for
delimiting text lines. There's precedent for the latter approach too
(see, for example, Java), but Unix gives a powerful precedent for
having a uniform internal convention for representing text streams.


However the user should be aware that everything breaks down if the
input system tries to handle a file as text when that file doesn't
adhere to the conventions for text on the system. Thus a
windows/dos file bodily transferred to a linux system will have
those extraneous '\r's. A linux file transferred to windows may
appear to be one long line with no '\n's.

Some programs deliberately treat all files as binary, and try to
make their own decisions about the format. I believe gcc is one of
these.

--
"If you want to post a followup via groups.google.c om, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
More details at: <http://cfaj.freeshell. org/google/>
Also see <http://www.safalra.com/special/googlegroupsrep ly/>
May 15 '06 #51
Chris Hills wrote:
<cb********@yah oo.com> writes

.... snip ....\

One loosening that might be worthwhile is advice on how to make
various almost-C compilers hew to the various standards, and
their failings.


Why would they want to? The job of standards is to standardise industry
practice not go off on a whim and expect the industry to follow. That
is the problem with C at the moment. It has gone in a direction the
industry does not want to follow.

Others have commented on the failings of the standards including people
on the standards panels.


You misconstrued. For example, to bring gcc into conformity one
can use "-W -Wall -ansi - pedantic". The 'they' is the user.

--
"If you want to post a followup via groups.google.c om, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
More details at: <http://cfaj.freeshell. org/google/>
Also see <http://www.safalra.com/special/googlegroupsrep ly/>
May 15 '06 #52
"CBFalconer " <cb********@yah oo.com> wrote in message
news:44******** *******@yahoo.c om...
"P.J. Plauger" wrote:
"S.Tobias" <si***@FamOuS.B edBuG.pAlS.INVA LID> wrote in message
... snip ...
Why is there the text mode in the first place? All operations valid
for text streams seem to be valid for binary ones, too. Text streams
are more difficult to handle (eg. you can't calculate offsets, there's
some extra undefinededness ). Apart from system compatibility, is there
any advantage to opening files in text mode?


System compatibility is a damned important reason. Every system has its
own convention for representing text files, as created by text editors
and consumed by other text-processing programs. If that convention
doesn't
match the C convention -- zero or more lines of arbitrary length, each
terminated by a newline -- somebody has to do some mapping. Whitesmiths,
Ltd. introduced the text/binary dichotomy in 1978 when porting C to
dozens of non-Unix systems, and other companies did much the same thing
in the coming years. It was a slam dunk to put it in the draft C Standard
begun in 1983.

If you try to live with just binary mode, then every program either has
to map text files for itself or tolerate a broad assortment of rules for
delimiting text lines. There's precedent for the latter approach too
(see, for example, Java), but Unix gives a powerful precedent for
having a uniform internal convention for representing text streams.


However the user should be aware that everything breaks down if the
input system tries to handle a file as text when that file doesn't
adhere to the conventions for text on the system.


Well, yes.
Thus a
windows/dos file bodily transferred to a linux system will have
those extraneous '\r's. A linux file transferred to windows may
appear to be one long line with no '\n's.
You mean, no '\r's I assume.
Some programs deliberately treat all files as binary, and try to
make their own decisions about the format. I believe gcc is one of
these.


Could be, but IIRC it gets bent out of shape if a backslash macro
continuation is not immediately followed by a newline. So its effort
is only half hearted.

Put simply, there's no substitute for making all text files on a
system obey the conventions for text files on that system.

P.J. Plauger
Dinkumware, Ltd.
http://www.dinkumware.com
May 16 '06 #53
"P.J. Plauger" wrote:
"CBFalconer " <cb********@yah oo.com> wrote in message

.... snip ...
Thus a
windows/dos file bodily transferred to a linux system will have
those extraneous '\r's. A linux file transferred to windows may
appear to be one long line with no '\n's.


You mean, no '\r's I assume.


No, I meant what I said. I am assuming the text input system looks
for the sequence \r\n before transmitting a \n. The other
(probably more likely) interpretation will just work, and nobody
need worry unduly about that. And I did say 'may appear'.

--
"If you want to post a followup via groups.google.c om, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
More details at: <http://cfaj.freeshell. org/google/>
Also see <http://www.safalra.com/special/googlegroupsrep ly/>
May 16 '06 #54

CBFalconer wrote:
However the user should be aware that everything breaks down if the
input system tries to handle a file as text when that file doesn't
adhere to the conventions for text on the system. Thus a
windows/dos file bodily transferred to a linux system will have
those extraneous '\r's. A linux file transferred to windows may
appear to be one long line with no '\n's.

Some programs deliberately treat all files as binary, and try to
make their own decisions about the format. I believe gcc is one of
these.


I'm fairly new to C and especially to ANSI/ISO C, but it seems somewhat
strange to me that the Standard (AFAIK) doesn't attempt to regulate
this aspect of the language as far as the standard file descriptors go.
For example, to me it would seem logical to *always* open stdin in text
mode, so that redirected input would work correctly regardless of the
platform, since I think it's fair to say that most redirected input to
real-world apps and command-line utilities is in the form of text files
and not binary data files. Some (most?) compilers will link code into
compiled programs to choose the "best" mode for stdin based on how you
give your C programs input. Cygwin gcc is one example: it puts stdin in
text mode if no redirection occurs; however, if you are redirecting
input from a file (even if it's a text file), it will switch stdin into
binary mode, unless you a) explicitly force stdin into text mode in the
source code or b) override this behavior with an external environment
variable.... Wouldn't it make more sense to clearly define this
behavior instead of leaving it to the whim of the specific compiler you
happen to using at the moment? For example, why not have something in
the Standard to the effect of: "Upon entering main(), the standard
streams stdin, stdout, and stderr shall be in text mode"? Then the
programmer need not worry about compiler quirks like the one I
mentioned above when parsing text files from redirected input, since
newline translation would be guaranteed to occur unless or until the
programmer explicitly switches a stream from text mode into binary mode
at the source-code level.

Being a C newcomer and a complete novice in all things Standard, I
wouldn't be at all surprised if my argument here is overly simplistic
or even unfounded. What are your (everyone's) thoughts on this idea, or
has it already be discussed and discarded, or beyond the scope of what
the Standard is meant to define? I'm interested to see your thoughts
and comments on this.

Mike S

May 16 '06 #55
Mike S wrote:
For example, why not have something in
the Standard to the effect of: "Upon entering main(), the standard
streams stdin, stdout, and stderr shall be in text mode"? Being a C newcomer and a complete novice in all things Standard, I
wouldn't be at all surprised if my argument here is overly simplistic
or even unfounded.


N869
7.19.3 Files
[#7] At program startup, three text streams are predefined
and need not be opened explicitly -- standard input (for
reading conventional input), standard output (for writing
conventional output), and standard error (for writing
diagnostic output).

--
pete
May 16 '06 #56
On Mon, 15 May 2006 13:58:28 UTC, Flash Gordon
<sp**@flash-gordon.me.uk> wrote:

Without text streams how can you produce a C source file that is
guaranteed to produce a valid text file on whatever system you run the
program on? Historically systems have used rather more schemes than just
terminating lines with CR, CRLF or LF,
It is simple. A stream is an absract form of data I/O. There is
nothing that requires that a C program has to see cr or lf or cr/lf on
the dource for input or output stream. When the underlying OS says
that a line is a record of fixed lengh, or variable lenth with some
special hints how long the record is or uses some 17 bit special code
on 42 bit chars it would simple the C runtime that will produce a line
that contains \n on the real end (not identical with the physical end
of the record anyway and will extend an empty line "\n" to the given
format.

That is wh a stream is defined as abstract and has nothing to do with
the physical layout of physical data unit it is stored on. That is
because the standard says not a single word about screen, keyboard,
printer, disk....... but says stream to anything.

There are really some systems around using fixed records, records with
variable lengh and so on. Get conforming C source and use a compiler
that is able to compile it to that target and each conforming program
will work.

some have used some form or record format, e.d. the first couple of bytes on a line saying how long
the line is.
Yeah, but when you use the I/O defined in the standard you have no
need to know how data is written.
Who is to say that in the future a system might not choose to encode the
file type as a mime header? Then the system might not even let you open
a text file as a binary file, or open a binary file as a text file, and
such restrictions could be useful. Also, on such a system, if you
created a file as a binary file the normal text editor of the system
might refuse to open it!

So the compatibility aspect is pretty major.


That is given since BCPL, the predecessor of C already. That is why C
does nothing knows about directories too.

When your program has a need to handle directories or exact knowledge
of how data gets written you has to use system specific functions and
leaves the area of conforming C programs.

The standard defines the minimal requirements an C implementation have
to fullify but lets enough room to the implementation to do it the
best way its underlying OS in hosted environment or the pure
implementation on freestanding environment can fit.

--
Tschau/Bye
Herbert

Visit http://www.ecomstation.de the home of german eComStation
eComStation 1.2 Deutsch ist da!
May 16 '06 #57
On Mon, 15 May 2006 14:21:52 UTC, Kenneth Brody <ke******@spamc op.net>
wrote:
Richard Heathfield wrote:
[...]
The newline marker defined by C is '\n'.

[... How various systems "really" store EOL in a file ...]
On the mainframe - well, you /really/ don't want to know.

[...]

I recall using a "mainframe" (okay, really a micro version of a mainframe)
that didn't have any "end of line marker" in text files. Instead, each
line started with two bytes containing the length of the line, and the
contents would be padded to an even number of bytes. So, a text file with
two lines -- "hi" and "there" -- would actually contain thissequence of
bytes:

0x02, 0x00, 'h', 'i', 0x05, 0x00, 't', 'h', 'e', 'r', 'e', 0x00

This is also a perfect example why you can't pass arbitrary values to
fseek().

Yeah, but you would run the classic "hello world\n" program
successfully without knowing that details of that implementation. This
is one of the points that makes C so highly portable.

--
Tschau/Bye
Herbert

Visit http://www.ecomstation.de the home of german eComStation
eComStation 1.2 Deutsch ist da!
May 16 '06 #58
Herbert Rosenau wrote:
On Mon, 15 May 2006 13:58:28 UTC, Flash Gordon
<sp**@flash-gordon.me.uk> wrote:
Without text streams how can you produce a C source file that is
guaranteed to produce a valid text file on whatever system you run the
program on? Historically systems have used rather more schemes than just
terminating lines with CR, CRLF or LF,


It is simple. A stream is an absract form of data I/O. There is


<snip>

I think you are in violent agreement with me. I was responding to a
questions about why C has text streams as well as binary streams with an
explanation of the problems if it did not. You are explaining why C
programs see an abstraction (e.g. text and binary streams with the
system) specifics handled at a lower level.
--
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

Inviato da X-Privat.Org - Registrazione gratuita http://www.x-privat.org/join.php
May 16 '06 #59
"Mike S" <mg******@netsc ape.net> writes:
I'm fairly new to C and especially to ANSI/ISO C, but it seems somewhat
strange to me that the Standard (AFAIK) doesn't attempt to regulate
this aspect of the language as far as the standard file descriptors go.
For example, to me it would seem logical to *always* open stdin in text
mode, so that redirected input would work correctly regardless of the
platform, since I think it's fair to say that most redirected input to
real-world apps and command-line utilities is in the form of text files
and not binary data files.


The Standard refers to the standard streams as "standard text
streams", so presumably they are supposed to be in text mode.
--
"When in doubt, treat ``feature'' as a pejorative.
(Think of a hundred-bladed Swiss army knife.)"
--Kernighan and Plauger, _Software Tools_
May 16 '06 #60

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

Similar topics

8
3461
by: Bernhard Hidding | last post by:
Hi, my program writes chars to an ascii file via ofstream. You can use "\n" for newline and "\t" for tab there, but is there any command that deletes the last char in the current ofstream? Thanks in advance, Bernhard
2
3303
by: anirudhvr | last post by:
Hi, I needed a basic binary to ascii encoder, so I wrote this piece of code: /* Encoding algo: suppose 11111010 is the byte to be encoded. It is first broken up into two 4-bit parts (1111 and 1010) This 4-bit quantity is then padded between a 01 and a 10, ie, 01xxxx10 will be written out to the output file.
31
3237
by: Claude Yih | last post by:
Hi, everyone. I got a question. How can I identify whether a file is a binary file or an ascii text file? For instance, I wrote a piece of code and saved as "Test.c". I knew it was an ascii text file. Then after compilation, I got a "Test" file and it was a binary executable file. The problem is, I know the type of those two files in my mind because I executed the process of compilation, but how can I make the computer know the type of a...
6
10047
by: SandyMan | last post by:
Hi, I am able to open a binary file for reading but can someone tell me as how to go about converting a Binary file to ASCII file using C. Thanks In Advance SandyMan
5
10716
by: veg_all | last post by:
I have a script where a user can upload their csv file into a mysql database. The problem is sometimes a user will upload the raw excel or access file. How can I perform some simple checks to determine if the file is binary. I could do some regular expressions to check for unusual characters, but how would I read the file line by line?
1
1408
by: rsr | last post by:
Hi everybody, I have a VC++ application to connect two computers with a serial cable. Can anyone of u tell me which scheme of encoding is used to transmit data?..Binary or ASCII.. I guess its Binary as I am able to transmit even special characters like Δ(delta), alpha, beta..But I am not sure.. Thanks in advance
24
3023
by: pbd22 | last post by:
Hi. I want to know the size of a file (prior to FTP) in ASCII Mode. The reason is that I want to know how bit the file is going to be once it reaches the FTP server and there is a size difference between binary and ascii mode (100 or so bytes). So, how do I get the size of the file in ASCII Mode using the usual VB.NET API?
2
3900
by: tedpottel | last post by:
Hi, My program has the following code to transfer a binary file f = open(pathanme+filename,'rb') print "start transfer" self.fthHandle.storbinary('STOR '+filename, f) How can I do an ASCII file transfer?????? -Ted
1
2607
by: Vic | last post by:
I have a c program which writes mac address entries onto a text file. Text file when opened in vim looks like this index mac 1 ^@^@^Q^@^@^A ascii of (00.00.11.00.00.01) 2 ^@^@^Q^@^@^B ascii of (00.00.11.00.00.02) .. ........ Likewise I read the mac entries from the text file using a perl script and do some processing
0
9931
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
11108
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10725
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10830
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9557
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7956
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5781
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5978
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3226
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.