redirecting output

Henry Spencer henry at zoo.toronto.edu
Sat Jun 30 03:24:29 AEST 1990


In article <JASON.90Jun28152010 at oswine.cs.odu.edu> jason at cs.odu.edu (Jason C Austin) writes:
>	freopen will do the job for you.  In fact the unix manual page
>says that this command is mostly used for this purpose.
>
>	freopen( "filename", "w", stdout );

You have the right idea, but you left something out.  Try this instead:

	#define	FILENAME	"filename"
	if (freopen(FILENAME, "w", stdout) == NULL) {
		fprintf(stderr, "freopen on `%s' failed", FILENAME)
		exit(1);
	}

God is not on your side; such a call *will* fail eventually.  Life is
much more pleasant if your code copes properly.
-- 
"Either NFS must be scrapped or NFS    | Henry Spencer at U of Toronto Zoology
must be changed."  -John K. Ousterhout |  henry at zoo.toronto.edu   utzoo!henry



More information about the Comp.lang.c mailing list