473,461 Members | 1,929 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

passing a va_list to sprintf

I have a function:

void f(char* format, ...)
{
va_list args;
char buf[128];
sprintf(buf, format, args);
printf(buf);
}

But I can't get sprintf to properly take the args I have given to f(). I can't
seem to find any examples on passing a va_list.

Any help would be appreciated.

Thanks.

~S

Nov 13 '05 #1
3 28143
nrk
Shea Martin wrote:
I have a function:

void f(char* format, ...)
{
va_list args;
char buf[128];
sprintf(buf, format, args);
printf(buf);
}

But I can't get sprintf to properly take the args I have given to f(). I
can't seem to find any examples on passing a va_list.

Any help would be appreciated.

Thanks.

~S


What you want is vsprintf and not sprintf. Remember to call va_start before
making the call to vsprintf and call va_end after the call returns. Look
up your favorite C book or manual for more details.

-nrk.
Nov 13 '05 #2
"Shea Martin" <sh**@snowsquirrel.ca> wrote in message
news:kooob.230908$pl3.90584@pd7tw3no...
I have a function:

void f(char* format, ...)
{
va_list args;
char buf[128];
sprintf(buf, format, args);
printf(buf);
}

But I can't get sprintf to properly take the args I have given to f(). I can't seem to find any examples on passing a va_list.

Any help would be appreciated.


Try vsprintf.
Nov 13 '05 #3
Shea Martin wrote:
I have a function:

void f(char* format, ...)
{
va_list args;
char buf[128];
sprintf(buf, format, args);
printf(buf);
}

But I can't get sprintf to properly take the args I have given to f().
I can't seem to find any examples on passing a va_list.

Any help would be appreciated.

Thanks.

~S

Thanks for the solutions, worked perfect.
~S

Nov 13 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Simon L | last post by:
Morning all, I'm converting my windows exe into a windows service and to get some log information I'm replacing TRACE with my own Log. Since some of the Trace statements take a number of...
2
by: OneLG13 | last post by:
I have a program that uses a scripting language that does not support formating strings with a printf syntax. Thus, I am writing a plugin to add the functionality. The entry point and argument...
2
by: Joerg Schoen | last post by:
Hi folks! I have a function that gets a 'va_list'. I am passing the 'va_list' two times to a function like 'vprintf' to print it out. I thought that this was portable until I came across a...
2
by: Andrej Prsa | last post by:
Hi! If I declare two functions like this: int execute_command (char *name, ...) { va_list args; va_start (args, name); my_func (1, args);
9
by: Matt Garman | last post by:
I'm trying to develop (for my own personal use) a general "messaging facility" in C. The idea is that the facility will be used for both debugging/logging and user interfacing. I'd like it to be...
11
by: thierrydollar | last post by:
Hi, I have written a very simple program using variable arguments calls and I get strange things that I cannot explain. I have one function (add) that displays two parameters. It works well...
5
by: coltrane | last post by:
Is it possible to have a function with variable number of parameters pass the parameters to another method that takes variable number of params? maybe something like this void vfoo2( const...
7
by: Flash Gordon | last post by:
Reading the standard, va_list is an object type (, so I believe the following should be possible: #include <stdarg.h> void foo(va_list *arg) { /* do some stuff which conditionally might read...
1
by: Anup Gupta | last post by:
imsc_int32_t imsc_wsprintf( OUT imsc_wchar_t *s, IN imsc_wchar_t *format, ...) { va_list ap; imsc_int32_t dNumBytes; va_start(ap, format); dNumBytes = swprintf(s,format, ap);...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.