Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pass "generic" type variable

Status
Not open for further replies.

CJason

Programmer
Oct 13, 2004
223
US
I'm wanting to create a function that accepts a format, "%d" or "%s" or etc.. (for example), and a value, then this function converts the value to a string. So, something like this:

int my_func(char* fmt, ?value?) {
char* str;
sprintf(str,fmt,value);
return;
}

How can I do this? What do I declare for "value" in the call? OR, is this even possible??

Thanks in advance!!!
 
Note that there are two headers for the ellipsis: one for old C programs and one for new stuff. You should be using stdarg.h. The old one can behave slightly differently.

Also, you can't pass the ellipsis from one routine to another.
 
> Also, you can't pass the ellipsis from one routine to another.
But you can pass a valist as a parameter.

CJason's code for example could call va_start, then call vsprintf()


--
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top