UMBC CS 201, Fall 98
UMBC CMSC 201 & 201H Fall '98 CSEE | 201 | 201 F'98 | lectures | news | help

Command Line Arguments

When a C program begins execution the shell passes parameters to the main program function that reflect the command line that began the program.
 
    void main(int argc, char *argv[])
Where:

Program

#include <stdlib.h> #include <stdio.h> main(int argc, char *argv[]) { int i; printf("%s called with %d arguments:\n",argv[0], argc); for(i = 0; i < argc; i++) { printf(" argv[%d] = %s\n", i, argv[i]); } }

Output

% cc args.c % a.out foo bar 13.3 mumble 2 a.out called with 6 arguments: argv[0] = a.out argv[1] = foo argv[2] = bar argv[3] = 13.3 argv[4] = mumble argv[5] = 2


CSEE | 201 | 201 F'98 | lectures | news | help

Sunday, 08-Nov-1998 15:57:31 EST