read/write same file with one open -- Query

utzoo!decvax!harpo!eagle!mhtsa!alice!rabbit!ark utzoo!decvax!harpo!eagle!mhtsa!alice!rabbit!ark
Thu Jan 27 17:48:50 AEST 1983

UNIX System III and, I believe, Berkeley UNIX allow a file to
be opened read/write.  You say:

	FILE *f;
	f = fopen("file", "r+");

(or "w+")  The + means that you can read and write.  WARNING:
If you have been reading and you want to write, or vice versa,
you must "switch modes."  This can be done by executing
lseek or rewind on the file.  Normally you will do one of these
anyway when changing.  (change lseek to fseek in the above line)
Note that fseek(f,0L,1) is a no-op, except that after you do it,
you can either read or write the file.

More information about the Comp.lang.c mailing list