Command Line Arguments

argc is the number of arguments on the command line including the program name; argument count

 

argv contains the actual arguments; argument value

 

argv[0] contains the name of the program, argv[1] is the first argument, and so on.

 

#include <stdio.h>

int main( int argc, char *argv[] )
{
	for( int myNum = 0; myNum < argc; myNum++ )
	{
		puts( argv[myNum] );
	}
	return 0;
}

Compile & run:

example.exe
one
two
three

Leave a Reply