>> SPEAKER: Up until now, in programs we've written, we've declared main as
int main void.
And all this time, that void has simply been specifying that the
program does not take any command line arguments.
In other words, when a user runs a program, he or she can provide command
line arguments by writing additional words or phrases after the program's
name at the prompt.
>> Well, if you do want your program to take command line arguments, one or
more such words, we need to replace void with a couple of arguments.
So let's do that.
Include CS50.h.
Include standard io.h.
Int, main, and now instead of void, I'm going to specify an int called
argc, and an array of strings called argv.
>> Now, argc and argv are simply conventions.
We could've call these arguments most anything we want.
But what is important is that argc is an int, because by definition, it is
going to contain the argument counts, the number of words in total that the
user has typed at his or her prompt.
>> Argv, meanwhile, argument vector, is going to actually be an array storing
all of the words that the user has typed at his or her prompt.
Let's proceed to do something now with one or more of these
command line arguments.
In particular, let's go ahead and print whatever word the user types
after the program's name at the prompt.
>> Open bracket, closed bracket, print f, percent s, backslash n, comma.
And now I need to tell print f what value to plug into that placeholder.
I want the first word that the user has typed after the program's name.
And so I'm going to specify argv bracket 1, closed
parenthesis, semicolon.
>> Now, why bracket 1 and not bracket 0?
Well, it turns out, automatically stored in argv 0 is going to be the
program's actual name.
So the first word that the user types after the program's name is, by
convention, going to be stored in argv 1.
>> Let's now compile and run this program.
Make argv 0 dot slash argv 0, and now a word like hello, enter.
And there we have it, hello.