Xref: utzoo comp.lang.c:9257 comp.unix.questions:6555 comp.unix.wizards:7752 Newsgroups: comp.lang.c,comp.unix.questions,comp.unix.wizards Path: utzoo!utgpu!jarvis.csri.toronto.edu!dgp.toronto.edu!flaps From: flaps@dgp.toronto.edu (Alan J Rosenthal) Subject: Re: Writing to A NON-Existing File in "C" Message-ID: <8804082038.AA22418@explorer.dgp.toronto.edu> Keywords: C program, NON-EXISTING File, flushed results Organization: University of Toronto References: <9654@jplgodo.UUCP> <10285@steinmetz.steinmetz.ge.com> Distribution: na Date: Fri, 8 Apr 88 14:38:03 EDT davidsen@crdos1.UUCP (bill davidsen) writes: > if (outflag) fseek(fp, 0L, 2); /* rewind if open ok */ That's "fseek(fp,0L,0)". The given fseek() call seeks to the end of the file. > #define cprintf if (outflag) fprintf This kind of macro is very unsafe. Consider: if(something) cprintf(blah blah); else something else; The `else' clause will pair with the if in the cprintf expansion, much to your surprise and irritation. When at all possible, define macros to be expressions rather than larger amounts of code. For example: extern int fprintf(),mydonothing(); #define cprintf (outflag ? fprintf : mydonothing) and, elsewhere: int mydonothing() { return(0); } Some adjustments are needed to make it valid ANSI C due to mydonothing()'s being variadic; I think fprintf() will be declared in stdio.h but I'm not sure. ajr -- "Comment, Spock?" "Very bad poetry, Captain."