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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calling C++ prog with variable number of arguments

Status
Not open for further replies.

tewari68

Programmer
Jan 25, 2005
87
US
Hi,
I have a C++ prog. which is to be called by either 4 or 5 arguments, i.e. it is always called with 4 arguments however sometimes it might be called with an optional 5th argument.
How do we cope with this situation.
The prog. breaks if only four arguments are passed, 5th being optional and not being passed.

Appreciate any help
Thanks
 
If [tt]main[/tt] is declared as
Code:
int main( int argc, char *argv[] )
then [tt]argc[/tt] is the number of arguments passed, plus one for the command name.
 
hi

you can use <stdarg.h> header file for variable argument passing to c/c++ program,and macros you will have to use for this are

1.va_start
2.va_arg
3.va_list

best of luck
 
That's incorrect.

You might use the <stdarg.h> macros for retrieving variable arguments passed to a function, but not to a program. Not in any existing C or C++ implementation, anyway.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top