delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/10/20/04:52:50

Date: Mon, 20 Oct 1997 10:51:28 +0200 (MDT)
From: Thomas Knudsen <tk AT geb DOT gfy DOT ku DOT dk>
To: djgpp AT delorie DOT com, Peter Palotas <blizzar AT hem1 DOT passagen DOT se>
Subject: Re: sprintf() string length?
In-Reply-To: <3.0.16.19971016132047.34a756c4@hem1.passagen.se>
Message-ID: <Pine.SGI.3.95.971020104317.12222A-100000@geb.gfy.ku.dk>
MIME-Version: 1.0

On Thu, 16 Oct 1997, Peter Palotas wrote:

(...)
> >
> >I once read a solution to this (can't remember where though!):
> >
> >The "fprintf" command will return the number of characters output,
> >and you should fopen DOS's "NULL" file to send the output to.
> >"NULL" is a "black hole" which will swallow and ignore anything you
> >send to it.  Although "NULL" never appears in a directory, it
> >exists everywhere.  (I think the UNIX equivalent is "/dev/nul",
> >but I've never used UNIX.)
> 
> Does anyone know if this works, and how compatible it is?
> Writing to a NULL pointer doesn't sound too good to me!
> -- Peter Palotas alias Blizzar -- blizzar AT hem1 DOT passagen DOT se --
> 
(...)

It is not a matter of writing to a null pointer.
It is a matter of writing to a pointer pointing to the file with the name
/dev/null (or the file named "nul" in dos).
i.e.:

...
FILE *nowhere;
int  numchars;
nowhere = fopen("/dev/null", "w");
numchars = fprintf(nowhere, "how long is this string?");
...


Thomas

--
Thomas Knudsen                         | www:  http://www.gfy.ku.dk/~tk/
National Survey and Cadastre - Denmark | e-mail:            tk AT gfy DOT ku DOT dk
Geodetic office, Rentemestervej 8      | Direct Phone:   +45 35 87 52 64
DK-2400 Copenhagen NV, Denmark         | FAX:            +45 35 87 50 52



- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019