0

My code seems to compile fine but when I try checkcs50, it says: :( handles non-numeric key timed out while waiting for program to exit, what do you think the problem is?

#include <stdio.h>

#include <ctype.h> #include <cs50.h> #include <string.h> #include <stdlib.h>

int main(int argc, string argv[]) {

string t = argv[1];

if (argc != 2 || isdigit(t[0]) ==0 )
{
    printf("Usage: ./caesar key\n");
    return 1;

}
int cle = atoi(argv[1]);

string m = get_string("Please enter plaintext here: ");

printf("ciphertext: ");

for (int i = 0, p = strlen(m) ; i < p; i++)
{
     if (m[i] <= 'Z' && m[i] >= 'A')
    {
        printf("%c", (((m[i] - 'A') + cle) % 26) + 'A');
    }

    else if (m[1] <= 'z' && m[i] >= 'a')

    {
        printf("%c", (((m[i] - 'a') + cle) % 26) + 'a');
    }

    else

    {
        printf("%c", m[i]);
    }

}

printf("\n");
return 0;


{
    printf ("Usage: ./caesar key\n");
    return 1;
}

}

0

This isdigit(t[0]) ==0 only checks the first character of the command line argument. From the spec [emphasis added]

If any of the characters of the command-line argument is not a decimal digit, your program should print the message Usage: ./caesar key and return from main a value of 1.

2
  • so i need to change the isdigit for something else? – Mika-Anne Reha Dec 3 '20 at 18:42
  • add a for loop? – Mika-Anne Reha Dec 3 '20 at 19:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .