Writing to A NON-Existing File in \"C\"

Juergen Wagner gandalf at csli.STANFORD.EDU
Fri Apr 8 10:17:50 AEST 1988


Why all these lengthy solutions? As I tried to e-mail (host unreachable),
you could just do
	
# define do_output_p(file)	(!access((file),02))

and assign the result to a variable, say

static int do_output_flag;

main(...)
...
{
	char *file;
	...

	...
	do_output_flag = do_output_p(file);
	...
}

Then, to access the file use

# define Fopen      if (do_output_flag) fopen
# define Printf     if (do_output_flag) printf
# define Fclose     if (do_output_flag) fclose

Of course, another alternative would be just to open "/dev/null" instead of
the file specified.

Juergen "Gandalf" Wagner,		   gandalf at csli.stanford.edu
Center for the Study of Language and Information (CSLI), Stanford CA
-- 
Juergen "Gandalf" Wagner,		   gandalf at csli.stanford.edu
Center for the Study of Language and Information (CSLI), Stanford CA



More information about the Comp.unix.wizards mailing list