I'm working on pset2 from cs50 and am down to the last bug which I can't seem to wrap my head around. When I read my code, I AM using the parameter argv in line 3. Why the error message?
int main(int argc, string argv[]) // Will store argv[0] = ./caesar and argv[1] = key. Improve, check that argv[1] is only an int
{
int key = atoi("argv[1]");
if (argc != 2 || key <= 0)// Check that argv[0] is the file name as well? converts "key" (string) into int value
{
printf("Try again.");
}
string text = get_string("Plaintext: ");// Prompts user for plaintext
printf("Ciphertext: ");// Prints ciphertext
for (int i = 0, n = strlen(text); i < n; i++)// Example of good design bc doesn't have to check the length of the string on every iteration
{
if (isalpha(text[i]) == true && isupper(text[i]) == true)
{
int j = (int) text[i] % 65;
int k = (j + key) % 26;
char l = (char) k + 65;
printf("%c\n", l);
}
else if (isalpha(text[i]) == true && islower(text[i]) == true)
{
int j = (int) text[i] % 97;
int k = (j + key) % 26;
char l = (char) k + 97;
printf("%c\n", l);
}
else
printf("text[i]");
}
}