answersLogoWhite

0

The command line is represented in C or C++ as a call to main with two arguments...

int main (int argc, char* argv[]);

The argc variable is the number of arguments, and is always at least 1, because the first argument, argv[0], is the program name itself.

Each word in the command line is then presented in successive argv[n] variables. For instance, if you type thiscommand one two three, argc will be 4, and argv[n], n being 0 through 3, will be "thiscommand", "one", "two", and "three", without the quotation marks, of course.

Some implementations provide other functionality, such as an additional char *envp[] argument which contains the environment, but that is not ANSI. In the MS Windows environment, the entry point is to winmain for windows programs, and to main for console programs.

int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow);

In this case, the full command line is in lpCmdLine.

Other operating systems may have alternate entry points, but I do not know them as well as MS Windows. Other contributors - please refine this answer if appropriate.

User Avatar

Wiki User

14y ago

Still curious? Ask our experts.

Chat with our AI personalities

RossRoss
Every question is just a happy little opportunity.
Chat with Ross
FranFran
I've made my fair share of mistakes, and if I can help you avoid a few, I'd sure like to try.
Chat with Fran
TaigaTaiga
Every great hero faces trials, and you—yes, YOU—are no exception!
Chat with Taiga

Add your answer:

Earn +20 pts
Q: Command line argument in c plus plus?
Write your answer...
Submit
Still have questions?
magnify glass
imp