473,324 Members | 2,501 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

transfering variable length argument list

Is it possible to transfer a variable length argument
list? What I want to do is just

void myPrintf( char *pFormat, ... ) {
char buf[256];
sprintf( buf, pFormat, ... );
Jul 22 '05 #1
1 1630
ANDERS FLODERUS wrote in news:1p**************@nntpserver.swip.net:
Is it possible to transfer a variable length argument
list? What I want to do is just

void myPrintf( char *pFormat, ... ) {
char buf[256];
sprintf( buf, pFormat, ... );
.
.
.
return;
}

which obviously will not compile. If possible, I would
like to do it without using the va_... macros while stepping
throu the format specifier. I suppose it would be possible
althou I do not know what type the arguments are (could
be found in the format specifier?).


#include <cstdio>
#include <cstdarg>

void myPrintf( char const *pFormat, ... )
{
using namespace std;

char buf[256];

va_list va;
va_start( va, pFormat );

vsprintf( buf, pFormat, va );
/* _vsnprintf is non standard but your compiler may provide it.
If so its *safer* than the above.
*/
//_vsnprintf( buf, sizeof buf, pFormat, va );
va_end( va );

printf( "buf = [%s]\n", buf );
}

int main()
{
myPrintf("test %d", 1 );
}

HTH.

Rob.
--
http://www.victim-prime.dsl.pipex.com/
Jul 22 '05 #2

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

Similar topics

0
by: Philip Rittenhouse | last post by:
I have discovered a couple of problems with the way the universal gateway code handles optional parameters and variable argument lists in COM servers. It appears to only be a problem when you...
5
by: Jonathan Burd | last post by:
Greetings everyone, I wrote a function to learn about variable-length argument lists. I wonder if there is a better way to detect the end of the argument list than using a sentinel value like...
4
by: JH | last post by:
Fairly new to c# so please forgive any simple oversights. I'm developing a console app that loads dll assemblies at run time. The app scans a "plugin" directory for these dlls. Each dll is loaded...
3
by: Tomás | last post by:
Let's say we have a variable length argument list function like so: unsigned GetAverage(unsigned a, unsigned b, ...); I wonder does the compiler go through the code looking for invocations of...
6
by: Adam | last post by:
Hey, Just a quick appeal for suggestions re some code, able to pass varying numbers of arguments... I have a function which can accept varying numbers of arguments. It in turn calls a...
18
by: Pedro Pinto | last post by:
Hi there once more........ Instead of showing all the code my problem is simple. I've tried to create this function: char temp(char *string){ alterString(string); return string;
2
by: Daniel Reardon | last post by:
All, I'm sure that this is an old question, but I'm having problems getting a substring of a passed in variable. I can do other string manipulation with it such as concatonation, but I'm really...
8
by: Advait Mohan Raut | last post by:
Hello, I am using VC# 2005 ; C# 2.0 I am working on the performance measurement tool. For that I need my code to call user defined method along with its parameters. For that should I use a...
30
by: Adam | last post by:
Hi, I have a simple printf-like function: int print(const char *format, ...) { char buffer; va_list argptr; int i;
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.