![]() |
|
|||||||
|
|
Thread Tools | Search this Thread | Rate Thread |
|
#1
|
|||
|
|||
difference between "rb" mode file opening and "rt" mode file openingthe big diffrence between binary mode file opening and normal text mode file opening?
|
|
#2
|
||||
|
||||
Re: difference between "rb" mode file opening and "rt" mode file openingText 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
|
||||
|
||||
Re: difference between "rb" mode file opening and "rt" mode file openingQuote:
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:
Quote:
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
|
|||
|
|||
Re: difference between "rb" mode file opening and "rt" mode file openingQuote:
...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 GIDBlog
Python ebook by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The