E
Eric Lilja
As the title, says: Why doesn't the following program print Hi
Charles<newline> when run?
#include <stdarg.h>
#include <stdio.h>
static void va_arg_example(const char *format, ...)
{
va_list args;
va_start(args, format);
printf(format, args);
va_end(args);
}
int
main(void)
{
va_arg_example("Hi %s\n", "charles");
return 0;
}
The output is simply Hi<newline>
I tried running it under my debugger: Here's the contents of the variables
format and args when the printf-statement is reached:
(gdb) print args
$1 = 0x22ef64 ""
(gdb) print format
$2 = 0x403008 "Hi %s\n"
How do I fix it?
I encountered this problem in a much larger program involving a third-party
gui library but I hope I have boiled the problem to a short program using
only standard C constructs.
Thanks for reading and replying.
/ Eric
Charles<newline> when run?
#include <stdarg.h>
#include <stdio.h>
static void va_arg_example(const char *format, ...)
{
va_list args;
va_start(args, format);
printf(format, args);
va_end(args);
}
int
main(void)
{
va_arg_example("Hi %s\n", "charles");
return 0;
}
The output is simply Hi<newline>
I tried running it under my debugger: Here's the contents of the variables
format and args when the printf-statement is reached:
(gdb) print args
$1 = 0x22ef64 ""
(gdb) print format
$2 = 0x403008 "Hi %s\n"
How do I fix it?
I encountered this problem in a much larger program involving a third-party
gui library but I hope I have boiled the problem to a short program using
only standard C constructs.
Thanks for reading and replying.
/ Eric