I'm trying to solve pset2 Cesar encryption.Everything seems fine and encryption is working but when I hit check50 I get errors:
:( encrypts "a" as "b" using 1 as key
expected prompt for input, found none
:( encrypts "barfoo" as "yxocll" using 23 as key
expected prompt for input, found none
:( encrypts "BARFOO" as "EDUIRR" using 3 as key
expected prompt for input, found none
:( encrypts "BaRFoo" as "FeVJss" using 4 as key
expected prompt for input, found none
:( encrypts "barfoo" as "onesbb" using 65 as key
expected prompt for input, found none
Here is my code:
#include <stdlib.h>
#include <stdio.h>
#include <cs50.h>
#include <ctype.h>
#include <string.h>
int main(int argc, string argv[])
{
int iKey = 0;
string user_message;
if (argc < 2 || atoi(argv[0]) < 0 || atoi(argv[1]) < 0)
{
printf("enter a single command-line arg: non-negative integer.\n");
return 1;
}
else
{
iKey = atoi(argv[1]);
}
user_message = get_string();
// starting of encipher message
for (int i = 0, j = strlen(user_message); i < j; i++)
{
if (islower(user_message[i]) && isalpha(user_message[i]))
{
user_message[i] = (user_message[i] - 'a' + iKey) % 26 + 97;
}
else if(isupper(user_message[i]) && isalpha(user_message[i]))
{
user_message[i] = (user_message[i] - 'A' + iKey) % 26 + 65;
}
// print the encrypted text
printf("%c", user_message[i]);
}
printf("\n");
return 0;
}