Here is my code which works well even with non-numeric key.
#include <stdio.h>
#include <cs50.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
bool key_check(string s);
int main(int argc, string argv[])
{
int i, j;
if (argc == 2)
{
if (!key_check(argv[1]))
{
printf("Usage: ./caesar key");
return 1;
}
}
else if (argc != 2)
{
printf("Usage: ./caesar key");
return 1;
}
int n = strlen(argv[1]);
int m = atoi(argv[1]);
string cyphertext[n];
string plaintext = get_string("plaintext: ");
{
printf("ciphertext: ");
for (j = 0; j < strlen(plaintext) ; j++)
{
char t = plaintext[j];
if (isalpha(t))
{
char x = 'A';
if (islower(t))
{
x = 'a';
}
printf("%c", (t - x + m) % 26 + x);
}
else
{
printf("%c", t);
}
}
}
printf("\n");
return 0;
}
bool key_check(string s)
{
for (int i = 0, len = strlen(s); i < len; i++)
if (isdigit(s[i]))
{
return true;
}
return false;
}
I get the error as I mentioned when I use Check50 however when I try using non-numeric keys it works just fine. What is the issue here ?