cascading stdarg calls

  • Thread starter cornelis van der bent
  • Start date
C

cornelis van der bent

Hi, the code below prints a garbage "world" value to <messages>;
"Hello " is fine. What can be the problem?

static char messages[LARGE_ENOUGH];

int writeText(char* text, char* format, ...)
{
va_list argumentList;

va_start(argumentList, format);
vsprintf(text, format, argumentList);
va_end(argumentList);
}

void writeMessage(char* format, ...)
{
va_list argumentList;

va_start(argumentList, format);
writeText(protocolText, format, argumentList);
va_end(argumentList);
}

void test(void)
{
writeMessage("Hello %s!\n", "world");
}

Thanks,

Cornelis
 
C

cornelis van der bent

The problem is that you cannot call a function with "..." passing
it a va_list. You have to create a function accepting a va_list
as argument.

Thanks for the quick answer! It's already in my code now and of
course works.

Cornelis
 
S

Seebs

Hi, the code below prints a garbage "world" value to <messages>;
"Hello " is fine. What can be the problem?

A va_list is not the same as a series of arguments. You need to use
a va_list argument to writeText, not a ...

-s
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top