jharvard@appliance (~/Dropbox/pset2): ./caesar 13

Be sure to drink your Ovaltine!

Or fher gb qevax lbhe Binygvar!

This assignment required to execute like the above. However, if using int main (int argc, string argv[]), the key and the plaintext need to be entered immediately after the program name. How could I set to enter the program name + key only in Line 1 and then the plaintext in Line 2? In this case this can lead to the output in Line 3 which is what the quoted error message is about I believe.

Grateful if some guidance available as not good at this argv function. Thanks.

2 Answers 2


It's up to you to determine what you use argv[] for. In this program, you should expect the key to be entered on the command line (it will be stored in argv[1]) and for the plain text to be entered by the user once the program starts (using GetString() is a good way to do this).


I don't see any reason to why you need that, but getting away from argv[], you accomplish that in this way :

# include <iostream>
# include <cstring>
# include <cstdlib>
using namespace std;

string process(string plaintext, int n)
     //do your stuff here
     return "Hello";

int main(int argc, char* argv[])
     string plaintext;
     cout<<process(plaintext, atoi(argv[1]));   
     return 0;

Although most code is similar to C, but sorry for the code in c++, feel free to ask if you have any queries in it.

You must log in to answer this question.

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