Path: utzoo!mnetor!uunet!husc6!spdcc!kaos!blblbl!henrik From: henrik@blblbl.UUCP (Larry DeLuca) Newsgroups: comp.unix.wizards Subject: Re: Writing to A NON-Existing File in \"C\" Message-ID: <202@blblbl.UUCP> Date: 9 Apr 88 22:13:21 GMT References: <12840@brl-adm.ARPA> Organization: Camp Random, Lexington MA Lines: 24 Summary: a simpler approach to the problem ... In article <12840@brl-adm.ARPA>, mchinni@ardec.arpa (Michael J. Chinni, SMCAR-CCS-E) writes: > In a message from Michael Deutsch > dated 6 Apr 88 03:47:17 GMT he writes: > > 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. > I have a couple of suggestions. First, try writing to "/dev/null". > Second, a temporary file could be used ("mkstemp" in BSD or "tmpnam"/"tempnam" > and "tmpfile" in SysV). Last, a filename of personal choice could be created, > written to, and then deleted at the end of the program. Why not just open the file at the beginning, and use the file pointer returned to tell if you should write or not, i.e. if(fp != (FILE *) 0) fprintf(...); I usually encode things of this sort in a macro and it makes my life much easier. Also, if you don't have the file around in the first place, things will go much more quickly than writing to a temp file you're only going to delete, or writing to /dev/null. larry...