I managed to write the code for caesar and it presents the desired values as output.
However, when I execute check50, apart from a smiley on all other points, this is what I get:
:( handles non-numeric key timed out while waiting for the program to exit
I cannot understand what it means and cannot figure out how to solve it.
I would be very obliged if you could help me out.
Thank you so much!
#include <stdio.h>
#include <cs50.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, string argv [])
{
if (argc == 2 && isdigit(*argv[1]))
{
string t = argv [1];
int k = atoi ( t );
string s = get_string ("plaintext: ");
printf ("ciphertext:" );
for (int i = 0, n = strlen(s); i < n; i++)
{
char c = s[i];
if (isalpha (c))
{
if (isupper(c))
{
int x = ((int) c - 65 + k) % 26 + 65;
printf ("%c", (char) x);
}
else
{
int x = ((int) c - 97 + k) % 26 + 97;
printf ("%c", (char) x);
}
}
else
{
printf ("%c", c);
}
}
printf ("\n");
return 0;
}
else
{
printf("Usage: ./caesar key \n");
return 1;
};
}