Thread: Creating GUI
View Single Post
Old Apr 4th, 2006, 6:59 AM   #5
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
When you write the main function, you'll often write it like this:
int main ()
{
	...
}

While correct, that's shorthand for this:
int main (int argc, char* argv[])
{
	...
}

You have two variables here, argc and argv. The former is the number of parameters you pass to the application, and the latter the parameters themselves. Put another way, if we start our program like this:
program.exe My name "is Fred"
We have four parameters, so argc == 4. The first is stored in argv[0], and is the name of the program itself: program.exe. The second, in argv[1], is My. The last two, in argv[2] and argv[3] respectively, are name and is Fred.

That's all a bit abstract, so we'll write a program to demonstrate. Compile and run this - call it "params.exe" or something:
#include <iostream>

int main (int argc, char* argv[])
{
	std::cout << "argc = " << argc << std::endl << std::endl;
	
	for (int i = 0; i < argc; i++)
	{
		std::cout << "argv[" << i << "] = " << argv[i] << std::endl;
	}
}
Run it with parameters - for example, params.exe 10 foo "I like sausages" or something equally retarded - and see what happens. If you have any more questions, let us know.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote