Valhalla Legends Forums Archive | C/C++ Programming | Creating functions.

AuthorMessageTime
Final
I have always wonderd how do you make a function with an unset amount of arguements its just been bothering me for a while can someone explain or point me to the way.

Here what im wondering about.

Regular function set arguements.
void reg(int arg1,int arg2);

Unset
void uns(what goes in here);
Utilization
uns(25,26);

// A c++ function that uses unset arguement number I THINK.

sprintf ()
sprintf (buffer,"%s..ect",argument ,argument argument ,argument ...ect);
October 12, 2006, 5:32 AM
K
Here's how it works.

[code]
// declare the function:
void printf(const char* format, ...);
[/code]

at the beginning of the function:

[code]
va_list pa;
va_start (pa, format); // start the var args pointer at the first argument.
[/code]

when you need to read another argument:
[code]
// to read the next argument, call va_arg with the var args ptr and the type of the next argument.
uint32_t next_arg = va_arg(pa, uint32_t);
[/code]

when you're done:
[code]va_end(pa);
[/code]

hope this helps.
October 12, 2006, 7:50 AM
Rule
This tutorial may help: http://www.cprogramming.com/tutorial/c/lesson17.html
October 13, 2006, 1:51 AM
Final
Awsome guys thanks again. Im going to play around with it see if i can make something usefull lol.
October 13, 2006, 5:25 AM

Search