I'm having trouble getting my version of Caesar to compile. It keeps saying: error: use of undeclared identifier 'n' for (int i = 0; n = strlen(unencrypted); i < n; i++)
I thought maybe I was missing a library in the header but it appears I have all the correct libraries listed. I also can't get debug or help50 to work. They keep returning stating they can't run. Not sure what else to do. Any help is greatly appreciated.
Here is my code:
#include <stdio.h> #include <cs50.h> #include <stdlib.h> #include <string.h> #include <ctype.h>
int main(int argc, string argv[]) { // Command Line Argument if (argc != 2) { printf("Usage: ./caesar key\n"); return (1); } // Get the key from the user int k = atoi(argv[1]);
// Get the plaintext from the user
string unencrypted = get_string("plaintext: ");
printf("ciphertext: %s\n", unencrypted);
// Convert plaintext to ciphertext
for (int i = 0; n = strlen(unencrypted); i < n; i++)
{
if islower(unencrypted[i])
{
printf("%c", (((unencrypted[i] - 'a') + k) % 26) + 'a');
}
else if isupper(unencrypted[i])
{
printf("%c", (((unencrypted[i] - 'A') + k) % 26) + 'A');
}
else
{
printf("%c", unencrypted[i]);
}
printf("\n");
return 0;
}
}