Re: "NUL" device is missing

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: KM (konstmor_at_nospam_yahoo.com)
Date: 05/14/04


Date: Thu, 13 May 2004 20:36:59 -0700

Chuck,

> I'll probably stick with using the NUL device right now. I may end up
> taking the time later to implement my own format parser that calculates
the
> required # of bytes of storage required to hold the formatted string, but
I
> don't have time to do it right now.

What VC version you are building against?
The reason I am asking is that the issue has been fixed in C standard of 99
year. Only VC 2003 has peaked up the fix.
The fix was to pass NULL to _snprintf to count the number of characters
required for a specified formating string. Basically, you can make a call
like: _snprintf(NULL,0,"%...",...) and it will return you the number.

You can easy track this down exploring CRT source of VC. In VC 6.0
(sprintf.h, output.c, stdio.h) you may see that the string formating routine
subcalls do not check for NULL. In VC 2003 CRT, they do (output.c, write_xxx
functions called from _output). This may be a cure for you. Also, there is
another useful wrapper (don't know if it is ANSI compatible) -
_scprintf(char* format,...) - this will return the same number of characters
you need.

Hope this helps,
    KM



Relevant Pages