C examples for Function:main function
A program to list the command line arguments
#include <stdio.h> int main(int argc, char *argv[]){ printf("Program name: %s\n", argv[0]); for(int i = 1 ; i<argc ; ++i) printf("Argument %d: %s\n", i, argv[i]); return 0;// w ww. ja va 2 s .co m }
My source file for this program had the name Main.c, so I entered the following command to execute it:
Main first second_arg "Third is this"
Putting double quotes around the argument ensures that it is read as a single argument and not as three arguments.