I am working on pset2 vigenere problem. When I run ./vigenere I keep getting this message. I looked it up online and it seems like I did not check argv before use it (?). I do not know what does it mean since I did same thing in caesar problem and it works fine. How do I check argv then? My code is below:
1 Answer
Before you use argv[1]
you need to be sure it actually exists. You should check if argc
is 2 first. If it's not, then you can exit the program gracefully with an error message, as it says in the spec:
If your program is executed without any command-line arguments, with more than one command-line argument, or with one command-line argument that contains any non-alphabetical character, your program should print an error (of your choice) and exit immediately, with main returning 1 (thereby signifying an error).
-
To connect the dots a little more, review the following explanation of what argc and argv are: crasseux.com/books/ctutorial/argc-and-argv.html– Cliff BCommented Jul 18, 2018 at 21:18
-