1
2
3
4
5
6
7
8
9
DAVID J. MALAN: Suppose now that we want to print all of the command line arguments that a user types at the prompt and not just the first such word that he or she types after the program's name. Well, to do this we simply need a familiar construct, a loop, and A familiar printf statement. So let's combine the two-- for. 

And now I want to iterate over all of the command line arguments in ARGV. Now fortunately, I have access to the total number in ARGC. So let's start there. 

int i get 0; i is less than argc ; i++. Now the looping construct I've set up here is simply going to integrate from zero on up to the total number of arguments in ARGV. And now we need to something within each iteration of this loop. Let's, quite simply, print out the i-th such argument in ARGV. 

Open bracket close bracket printf %s backslash n close quote comma. And now I need to plug in the value. So if I want the i-th argument in ARGV, that can be expressed as ARGV bracket i , close parenthesis, semicolon. Let's save the file, compile it, and run it. 

Make ARGV1 dot slash ARGV1. But before I hit enter, I should probably provide some additional words at the command prompt. So I'm going to something like [? foo, ?] bar, and baz. And now I'm going to hit Enter. As expected, I see not only the program's name, which is in ARGV0. I also see [? foo, ?] bar and baz.