Re: confused abt file operations



Groovy hepcat Gordon Burditt was jivin' on Tue, 30 Aug 2005 18:33:01
-0000 in comp.lang.c.
Re: confused abt file operations's a cool scene! Dig it!

>>If I open a binary file in text mode and use text functions to
>>read it then will I be reading numbers as characters or actual
>>values?
>>What if I open a text file and read it using binary read functions.
>
>The difference between a binary and text file on most implementations

Just to clarify (for the OP's sake), all files are binary files. But
some store values represented as text while others store raw binary
values.
However, a file stream may be opened in either binary or text mode.
This may (depending on the system) cause some translation of the bytes
read in or written out. For example, on a particular system a newline
sequence may be stored as a carriage return character followed by a
line feed character but is translated to a single newline character
when read in.

>is either (a) none at all, or (b) the line ending (\n vs. \r\n vs.
>\n\r vs. something else). This doesn't rule out things like binary
>line numbers and line lengths preceeding the line with no end-of-line
>terminator, but these are very rare.

There may be other translations too. For example, one well known
system truncates a text stream after a certain control character is
written to it. (You alude to this below, Gordon.)

>What is a "text function"? There is no such division ("fread and
>fwrite are for binary, printf, fgets, fputs, scanf, etc. are for
>text" is a myth).

Partially true, but some functions naturally lend themselves to
reading/writing text while others are naturally more suited to
reading/writing binary values. Actually, some functions require their
input to be text or they write text. You wouldn't read a raw binary
value with fscanf(), for example, because it parses formatted text.
You could read text with fread(), but it won't parse it and extract
values from it (as fscanf() will).

>The practical effect is likely that you will see stray \r characters
>before or after \n characers if you read a text file as binary. If
>you read a binary file as text, some of the \r characters might
>vanish. You might see a binary file read as text somewhat shorter
>than expected if the binary file contains a text "end of file
>character" which is interpreted as such.

Right.

--

Dig the even newer still, yet more improved, sig!

http://alphalink.com.au/~phaywood/
"Ain't I'm a dog?" - Ronny Self, Ain't I'm a Dog, written by G. Sherry & W. Walker.
I know it's not "technically correct" English; but since when was rock & roll "technically correct"?
.



Relevant Pages

  • Re: Megami71
    ... offended by naked girls, don't click on the links below: ... Or, if you dig it but the community doesn't, tell them something about sex and travel under your breath and get it for yourself anyway. ... I still have to watch more of the anime to make up my mind about that. ... About bloody time we had my kind of character here; they seem to be in short supply this month. ...
    (rec.arts.anime.misc)
  • Re: Histogram of character frequencies
    ... to any valid character value). ... quits the loop without entering the body. ... we then use feof() to test for an end of file ... Dig the sig! ...
    (comp.lang.c)
  • Re: Im very confused(learning C)
    ... (as opposed to "int main(void)") ... output one character at a time." ... you're assigning the value EOF to c. ... Dig the even newer still, yet more improved, sig! ...
    (comp.lang.c)
  • Re: getchar() problem
    ... When I run this program and enter a character at the prompt, ... party libraries may provide extentions or add-ons that do what you ... Dig the even newer still, yet more improved, sig! ...
    (comp.lang.c)
  • Re: How to print ^M (ctrl M)
    ... character, you should ensure that the value of i is within the ... bit character set having values from 0 to 127, ... Is this line supposed to be in the for loop? ... Dig the even newer still, yet more improved, sig! ...
    (comp.lang.c)