I'm not sure how to include the input from the command-line arguement.
I try to set the arguments equal to variables, bu it's not working.
#include <stdio.h>
#include <cs50.h>
int main(int argc, char* argv[])
{
string hash = argv[0];
int key = argv[1] - '0';
printf("argc: %s \n", hash);
printf("key: %i \n", key);
}
I get the following error:
caesar.c:15:9: error: incompatible pointer to integer conversion initializing 'int' with an expression of type 'char *' [-Werror,-Wint-conversion]
int key = argv[2] - '0';
^ ~~~~~~~~~~~~~
1 error generated. make: *** [caesar] Error 1
EDIT:
I read in C Programming Language, 2nd Edition that arg[0] is the program name:
By convention, argv [ 0] is the name by which the program was invoked, so argc is at least 1. If argc is 1, there are no command-line arguments after the program name. In the example above, argc is 3, and argv [0I, argv [ 1], and argv[2] are "echo", "hello, ", and "world" respectively. The first optional argument is argv[ 1] and the last is argv[argc-1]; additionally, the standard requires that argv[ argc] be a null pointer.
changed my initialization as such and testing to ensure argc is correct:
if(argc!=2)
{
printf("Usage: ./crack k\n");
return 1;
}
string hash = argv[1];
int key = argv[2] - '0';