I want to use a given string (given as console app argument) within the main-method and don't know how to assign the console app argument to a string variable which is declared and used in the main method:
console:
~/substitution/ $ ./test FOEFJEOWJFWEFOJ (<- wanted argument)
code:
int main (int argc, char* argv[])
{
string argumentString;
In other words: How do I create a string argumentString with the content of the main-method argument argv[]?
Until now the following is my closest approach.. but with that code I get an "expected expression" with a pointer to key = argv[]
int main(int argc, char *argv[])
{
string alphabet = "abcdefghijklmnopqrstuvwxyz";
string plain;
string key;
string cipher;
int i;
int j;
int n;
int o;
if (argc > 2)
{
printf("Only 1 Argument allowed");
return 1;
}
if (argc < 2)
{
printf("./substitution KEY\n");
return 1;
}
key = argv[];
if (strlen(key) == 26)
{
int main(int argc, char *argv[])
{
string alphabet = "abcdefghijklmnopqrstuvwxyz";
string plain;
string key;
string cipher;
int i;
int j;
int n;
int o;
if (argc > 2)
{
printf("Only 1 Argument allowed");
return 1;
}
if (argc < 2)
{
printf("./substitution KEY\n");
return 1;
}
key = argv[1];
if (strlen(key) == 26)
{
Sooo damned easy... Couldn't see the forest because of the trees (sry, don't know the proper phrase in English).
It was all correct so far. There was just the need of the "1" in the key-assignment line ("0" would be the programm's name as argument). facepalm
:-)