Department of Electrical and Computer Engineering

The University of Texas at Austin

EE 360N, Fall 2003
Parsing Command Line Arguments

Here is some sample code that grabs the command line arguments of a program:

#include 

int
main(int argc, char* argv[]) {

	char *prgName   = NULL;
	char *iFileName = NULL;
	char *oFileName = NULL;

	prgName   = argv[0];
	iFileName = argv[1];
	oFileName = argv[2];

	printf("program name = '%s'\n", prgName);
	printf("input file name = '%s'\n", iFileName);
	printf("output file name = '%s'\n", oFileName); 
}
Here's a sample run:
tick% assemble ThisGoesIn.asm ThisComesOut.obj
program name = 'assemble'
input file name = 'ThisGoesIn.asm'
output file name = 'ThisComesOut.obj'

Question for the reader, what happens when you run this program without any command line arguments? How do you recommend fixing/preventing this problem?