enter image description here I am currently on CS50x’s PSET2, Caesar, trying to get a key from the user (the first step pretty much). I need to get the key from the user. I understand that it will be a string stored in argv2 and that I need to convert it to an integer. I am currently attempting to do so by calling the integer “key” and converting argv2 to it but get the following error message: use of undeclared identifier argv. I thought argv does not have to be explicitly defined or declared? Could anybody help me with this single line of code (lol cry)? Thank you!

The code is below. (excluding header files)

int main(int argc, string argv[]);

// 1. Getting the key from the user

int key = atoi(argv2);


It's an array, not a variable. argv2 is a variable name. You need to add square brackets to hold the index. argv[2] Of course, that assumes there are 2 parameters. If there's only 1 parameter, it's going to be a problem.

That answers the question in the text of your question. Now, let's move on to the issues of the screenshot. The semicolon ; on the end of line 6 breaks the code. The structure of a program is this:

int main(int argc, string argv[])
    // all code goes between these brackets

Then, of course, you'll probably run into the unused var error, but that's not really a problem. Just print out the contents of a var or use it somewhere. ;-)

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenace. ;-)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .