Click to See Complete Forum and Search --> : 'vararg' functions??


badri1
March 7th, 2006, 01:19 PM
Hey All -

I want to send a string as a formated string to a function... meaning

say the function name is LOG

so i want to do a function call as

LOG("The integer valu is %d",iValue);

this string shd go as "The integer valu is 10", if iValue is 10....

i tried declaring the function as

void LOGGER(char *chpLog, ...) // (i tried to use the eclips operator)
{
-------
}


but the value of chpLog is comming as "The integer valu is %d"... do any one know how to tackle this ??


I know we can format the string using sprintf or CString::Format()..... but all these requires another variable and memory ...which i dont want to spend...!!

can it be solved using 'vararg' functions??... does any one know its implementation????

stober
March 7th, 2006, 01:23 PM
your function declaration is correct, but you need to use vargs. see the example for vsprintf (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_crt_vsprintf.2c_.vswprintf.asp) .

badri1
March 7th, 2006, 01:33 PM
super dude... its worked fine