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

Passing command line arguments to a concole app?

Status
Not open for further replies.

TheMillionDollarMan

Programmer
Jun 10, 2002
132
US

Does anyone have some code snipet for this?
or
A key word I can use in the MS help?

I want to enter this at the DOS prompt
d:\MyApp.exe -Uusername -Ppassword -Ddatabase

MyApp.exe is a console app.

Thanks

VC++ 6.0
Win2K
 
Just declare your main function as

Code:
void main(int argc, char *argv[])
{
}

argc is the number of arguments on the command line, including the name of the program itself.

argv[] is an array of strings. Each string is an argument. However, argv[0] is the first argument, not the name of the EXE file.

So, for the command line:

Code:
d:\MyApp.exe -Uusername -Ppassword -Ddatabase

argc=4
argv[0]="-Uusername"
argv[1]="-Ppassword"
argv[2]="-Ddatabase"

HTH.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top