GIDForums  

Go Back   GIDForums > Computer Programming Forums > C Programming Language
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 14-Feb-2006, 20:11
jaininaveen jaininaveen is offline
New Member
 
Join Date: Jan 2006
Posts: 25
jaininaveen is an unknown quantity at this point

difference between "rb" mode file opening and "rt" mode file opening


the big diffrence between binary mode file opening and normal text mode file opening?
  #2  
Old 15-Feb-2006, 00:18
Paramesh's Avatar
Paramesh Paramesh is offline
Regular Member
 
Join Date: Sep 2005
Location: The Milky Way
Posts: 927
Paramesh is a jewel in the roughParamesh is a jewel in the roughParamesh is a jewel in the rough

Re: difference between "rb" mode file opening and "rt" mode file opening


Text files contain data that are ASCII text.
They contain ordinary readable characters such as characters, digits, punctuation, and some special characters such as tabs, line breaks, etc.

A Binary file contains non-readable, or only binary characters.
It is a collection of 0s and 1s.

A text file can be considered as a special case of binary files, where text is encoded in the ASCII format.

For more information, visit Wikipedia:
Text_File
Binary_File

Also, text files have lines of text, along with end of line marker at the end of each line.
Whereas, binary files does not. They are not split up into lines or records.

This marker depends upon which operating system you are using.
Macintosh: x'0D'
Unix Based: x'0A'
Windows: x'0D0A'

Reading from a text file is far more easier than reading from a binary file.
Binary file handling is mainly done by using fread and fwrite, which deals with blocks of memories at a time.

Regards,
Paramesh.
__________________

Don't walk in front of me, I may not follow.
Don't walk behind me, I may not lead.
Just walk beside me and be my friend.
  #3  
Old 15-Feb-2006, 07:50
WaltP's Avatar
WaltP WaltP is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Midwest US
Posts: 3,258
WaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to all

Re: difference between "rb" mode file opening and "rt" mode file opening


Quote:
Originally Posted by Paramesh
Text files contain data that are ASCII text.
They contain ordinary readable characters such as characters, digits, punctuation, and some special characters such as tabs, line breaks, etc.

A Binary file contains non-readable, or only binary characters.
It is a collection of 0s and 1s.
This is a little too simplistic. All files contain only 1's and 0's. Binary files contain ASCII text.

The big difference is the text file will contain numbers in text mode which when read can be converted into ints and doubles. The binary file contains these values in their pure binary form and are read directly into an int or double without translation.

Quote:
Originally Posted by Paramesh
Also, text files have lines of text, along with end of line marker at the end of each line.
Whereas, binary files does not. They are not split up into lines of records.
Binary file can definitely be split up into records. Any database file is a binary file or records.

Quote:
Originally Posted by Paramesh
This marker depends upon which operating system you are using.
Macintosh: x'0D' -- carriage return
Unix Based: x'0A' -- line feed
Windows: x'0D0A' -- carriage return/line feed pair
When reading a text file, this 'marker' or EOL (End-Of-Line) indicator is translated into '\n' during the read. A binary read will not translate this marker and you will get the character(s) themselves, untranslated.

A binary file can be written directly from a C-structure, ASCII and numbers and all. It can then be read directly into that same structure without translating the data.
__________________

Got a cough? Go home tonight and eat a whole box of Ex-Lax. Tomorrow, you'll be afraid to cough.
-- Pearl Williams
  #4  
Old 15-Feb-2006, 14:15
davis
 
Posts: n/a

Re: difference between "rb" mode file opening and "rt" mode file opening


Quote:
Originally Posted by WaltP
A binary file can be written directly from a C-structure, ASCII and numbers and all. It can then be read directly into that same structure without translating the data.

...all good points WaltP, but some caveats should be applied to the idea of writing binary files and sucking them back into a structure. There are subtle nuances that must be considered when interacting with differing platforms, most notably big/little endian machines, sizeof( int) and, sometimes even byte alignment issues when structures are not on even byte boundaries.

Each of these can easily render the binary file "non-portable" for a given "struct" definition.

Also, for a given structure definition, the structure may contain only POD in most cases. In C++, where a structure may have constructors/destructors and other non-POD members, binary files can be done, but (usually) not in any way approaching simple or in any way supported by a language standard. Obviously, a non-POD approach to reading and writing binary files will not work with C, for example.



:davis:
 
 

Recent GIDBlogPython ebook by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 09:34.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.