fwrite(), fread(), fopen() & fclose() are all ANSI functions (and are
portable).
The others are low-level functions available on UNIX OS's and supplied by
many compiler vendors but not ANSI.
Generally the latter are unbuffered whereas you have control of buffering
for the former.
Stephen Howe
fwrite() uses FILE type filehandle,
write() uses int type filehandle.
write() may not be buffered, fwrite is buffered.
You should use write() when buffering is not desired :)
gonzo
==================================
Posted via http://nodevice.com
Linux Programmer's Site
The chief difference is that the f* functions are ANSI C functions, and the
others are POSIX functions. In comp.lang.c we discuss only ANSI C functions.
>When should I use fwrite()s? When are write()s preferable?
write is preferrable if portability to non-POSIX platforms doesn't matter,
and it's of utmost importance to eliminate copying overhead, or to have exact
control over communicating with some device.
The ANSI C functions are nice because they provide a buffered stream
abstraction. On POSIX platforms using getc() and putc() for single bytes is far
more efficient than using read() and write() for single bytes. But for
doing bulk transfers, it's more efficient to go directly to the system calls
and bypass the buffery layer.
Really? My Zog C documentation says that int write(char *filename, char
*title), given a suitable title, produces a novel, writing it to filename.
It returns 42 on success, and 98 on failure.
>
> write() may not be buffered, fwrite is buffered.
> You should use write() when buffering is not desired :)
But what if I want to write to a file, rather than produce a novel?
--
Richard Heathfield
"Usenet is a strange place." - Dennis M Ritchie, 29 July 1999.
comp.lang.c FAQ: http://www.eskimo.com/~scs/C-faq/top.html
> Really? My Zog C documentation says that int write(char *filename,
> char *title), given a suitable title, produces a novel, writing it
> to filename. It returns 42 on success, and 98 on failure.
Where I can download Zog C from ? Is it C99 compiler ?
Does it work on C-64 with tape recorder ?
> But what if I want to write to a file, rather than produce a novel?
Than you have to set the filename to be "/dev/nul".
>Richard Heathfield wrote:
>
>> Really? My Zog C documentation says that int write(char *filename,
>> char *title), given a suitable title, produces a novel, writing it
>> to filename. It returns 42 on success, and 98 on failure.
>
>Where I can download Zog C from ? Is it C99 compiler ?
>Does it work on C-64 with tape recorder ?
Its only available for Casio digital watches from 1989. So its more of
a C89 compiler...
>
>> But what if I want to write to a file, rather than produce a novel?
>
>Than you have to set the filename to be "/dev/nul".
Surely you mean /vmkernel? No, sorry, that would still produce a novel
result...
Mark McIntyre
I have been given to understand that at least one C99-compliant version is
under development. And there's an unsubstantiated rumour (which I just
started) that Kaz is doing a C99 version for the DS 9000 series.
> >Does it work on C-64 with tape recorder ?
Almost certainly.
> Its only available for Casio digital watches from 1989. So its more of
> a C89 compiler...
I think Mark is thinking of Zog C Lite. :-)
>
> >
> >> But what if I want to write to a file, rather than produce a novel?
> >
> >Than you have to set the filename to be "/dev/nul".
Unfortunately, /dev/nul doesn't mean a lot on a Casio digital watch.
> Surely you mean /vmkernel? No, sorry, that would still produce a novel
> result...
ROTFL!\b\b\b\b\b\bLOL\b\b\bHa ha ;-)