I have gotten my code to work for the caesar problem in problem set 2. However, when i check through check50 I run into this error: :( handles non-numeric key timed out while waiting for program to exit. Everything else works fine. I thought that using the isdigit() function handled non-numeric entries, but maybe I am misplacing or misusing the function. Here is my code so far:
#include <stdio.h>
#include <cs50.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
int main (int argc, string argv[])
{
if (argc !=2)
{
printf("Usage: ./caesar key\n");
return 1;
}
else
{
for (int i = 0, n = strlen(argv[1]); i < n; i++)
{
if (isdigit(argv[1][i]))
{
int key = atoi(argv[1]);
int letter;
int cipheredletter[30];
string plaintext = get_string("plaintext: ");
printf("ciphertext: ");
for (int j = 0, m = strlen(plaintext) ; j < m ; j++)
{
if (isalpha(plaintext[j]))
{
if (isupper(plaintext[j]))
{
letter = plaintext[j]-65;
cipheredletter[j] = (letter + key)%26;
cipheredletter[j] = cipheredletter[j]+65;
printf("%c",cipheredletter[j]);
}
else
{
letter = plaintext[j]-97;
cipheredletter[j] = (letter + key)%26;
cipheredletter[j] = cipheredletter[j]+97;
printf("%c",cipheredletter[j]);
}
}
else
{
cipheredletter[j] = plaintext[j];
printf("%c",cipheredletter[j]);
}
}
printf("\n");
return 0;
}
else
{
printf("Usage: ./caesar key\n");
return 1;
}
}
}
}