problem with fread/fwrite

Earl Chew cechew at bruce.cs.monash.OZ.AU
Sat Nov 17 17:38:13 AEST 1990


In <880 at jonlab.UUCP> jon at jonlab.UUCP (Jon H. LaBadie) writes:

>If in the stdio buffer I have the following;

>	Mary had a big sheep.  Supercalifragalisticexpalidocious ...
>	^

>With my pointer (read in this case) on the 'M', after I fread 23 bytes,
>so my buffer and pointer are such:

>	Mary had a big sheep.  Supercalifragalisticexpalidocious ...
>	                       ^

>what is wrong with fwrite'ing "Jack and Jill" on top of Super...?
>I.e. what is critical returning to some ground zero state before
>making a transition?

With `traditional' stdio implementations, the FILE will still be in `READING'
mode --- despite the fact that the fwrite() (or putc, etc) may `apparently'
succeed. However, when the buffer is exhausted, you will find that no write(2)
is performed (ie the fact that the buffer is dirty is not recorded) because of
the `READING' mode, and you will lose the data you wrote.

Earl
-- 
Earl Chew, Dept of Computer Science, Monash University, Australia 3168
EMAIL: cechew at bruce.cs.monash.edu.au PHONE: 03 5655447 FAX: 03 5655146
----------------------------------------------------------------------



More information about the Comp.lang.c mailing list