read/write same file with one op - (nf)

utzoo!decvax!harpo!seismo!hao!menlo70!sytek!zehntel!zinfandel!berry utzoo!decvax!harpo!seismo!hao!menlo70!sytek!zehntel!zinfandel!berry
Tue Feb 1 01:19:51 AEST 1983


#R:rabbit:-107800:zinfandel:14600002:000:630
zinfandel!berry    Jan 31 12:23:00 1983

/* What's wrong with this? It does stuff to the contents of a file and
   leaves the new stuff in the old file. */

#include <stdio.h>
main()
{
	FILE *in, *out;
	int c;

	/* diddle with a file... */
	in = fopen ( "input_file", "r");
	out = fcreat ("tmp_dooda", "w");
	while ( (c = fgetc ( in )) != EOF )
		fputc ( filter(c), out);
	fclose (in);
	fclose (out);
	unlink ( "input_file");
	link ( "tmp_dooda", "input_file");
	unlink ("tmp_dooda");
}

filter(c)
int c;
{
	/* do whatever it is you're doing here*/
	return mung(c);
}
	/* Berry Kercheval
	 * Zehntel Inc.
	 * (decvax!sytek!zehntel!zinfandel!berry)
	 * (415)932-6900
	 */




More information about the Comp.lang.c mailing list