The main( ) function in C has 2 arguments (= parameters):
#include <stdio.h> int main( int argc, char* argv[] ) { printf( "Hello World !\n" ); } |
argc = argument count is the # parameters given in the command line
argv = argument vector is the array variable containing the individual argument strings
Compared to Java: argc ~= Java's args.length argv[i] ~= Java's args[i]
|
The following for-loop prints the individual argument vector:
#include <stdio.h> int main( int argc, char* argv[] ) { for ( int i = 0; i < argc; i++ ) printf("%s\n", argv[i]); // prints argv[i] out } |
DEMO: /home/cs255001/demo/C/set1/args.c