Command line arguments Given after the name of a program in command-line cp f1 f2 gcc yourfilename Arguments are passed in to the program from the operating system Flexible But not required
How to Interpret A command-line interpreter explains the command The first word is treated as the name of a program Others as arguments. These strings are past to main function in C cp f1 f2 NULL cp f1 f2
How to Declare In C, these strings are past to the main function main() can actually accept two arguments number of command line arguments a full list of all of the command line arguments. Declaration int main ( int argc, char *argv[] )
How to use argc argv Argument count Number of strings – including executable file name argv Argument vector Size of argc+1 cp argv[0] argv[1] argv[2] f1 f2 NULL cp f1 f2
Example Copy file