Xref: utzoo comp.unix.questions:6439 comp.unix.wizards:7596 comp.lang.c:8939 Path: utzoo!mnetor!uunet!steinmetz!davidsen From: davidsen@steinmetz.steinmetz.ge.com (William E. Davidsen Jr) Newsgroups: comp.unix.questions,comp.unix.wizards,comp.lang.c Subject: Re: Writing to A NON-Existing File in "C" Message-ID: <10285@steinmetz.steinmetz.ge.com> Date: 6 Apr 88 14:23:31 GMT References: <9654@jplgodo.UUCP> Reply-To: davidsen@crdos1.UUCP (bill davidsen) Distribution: na Organization: General Electric CRD, Schenectady, NY Lines: 24 Keywords: C program, NON-EXISTING File, flushed results In article <9654@jplgodo.UUCP> deutsch@jplgodo.UUCP (Michael Deutsch ) writes: | | I have a "C" program that records the program | results into a file, provided that file already | exists. In case the file DOES NOT exist I want | the program to function identically but the results | should be flushed down the tube, i.e. nowhere, i.e. | written to a non-existing file? First problem is to open the file if it exists, by fp = fopen(MYFILE, "r+"); /* open, no create */ outflag = fp != NULL; /* set a flag */ if (outflag) fseek(fp, 0L, 2); /* rewind if open ok */ You can then print to the file using a macro, such as: #define cprintf if (outflag) fprintf . . cprintf(fp, "format", data); -- bill davidsen (wedu@ge-crd.arpa) {uunet | philabs | seismo}!steinmetz!crdos1!davidsen "Stupidity, like virtue, is its own reward" -me