It is the code for changing the cipher text from a plain text in cs50. I have tried with test case and it is giving the correct solution however when I try to use the cs50 checking command it shows an error which is out of my understanding. Can you guys help me with it? I am trying to find the error and what is causing the solution to be wrong.
This is my code
#include <cs50.h>
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
bool check(string num);
int main(int argc, string argv[])
{
// check if the command-line-argument is 2 characters
if (argc != 2)
{
printf("Invalid Keyn");
return 1;
}
else
{
string num = argv[1];
if (check(num) == true)
{
int key = atoi(num);
string ptext = get_string("Enter plain text:");
for (int i = 0; i < strlen(ptext); i++)
{
if (isupper(ptext[i]))
{
printf("%c", (ptext[i] - 65 + key) % 26 + 65);
}
else if (islower(ptext[i]))
{
printf("%c", (ptext[i] - 97 + key) % 26 + 97);
}
else
{
printf("%c", ptext[i]);
}
}
printf("n");
}
else
{
printf("Usage: ./caesar keyn");
return 1;
}
}
}
// check if the key is all digits
bool check(string num)
{
for (int k = 0; k < strlen(num); k++)
{
if (!isdigit(num[k]))
{
return 0;
}
}
return 1;
}
I keep getting this error message when it is actually showing the same results as it should be. I don’t understand what to do please help me.
Results for cs50/problems/2024/x/caesar generated by check50 v3.3.11
:) caesar.c exists.
:) caesar.c compiles.
:( encrypts "a" as "b" using 1 as key
expected "ciphertext: b...", not "bn"
:( encrypts "barfoo" as "yxocll" using 23 as key
expected "ciphertext: yx...", not "yxoclln"
:( encrypts "BARFOO" as "EDUIRR" using 3 as key
expected "ciphertext: ED...", not "EDUIRRn"
:( encrypts "BaRFoo" as "FeVJss" using 4 as key
expected "ciphertext: Fe...", not "FeVJssn"
:( encrypts "barfoo" as "onesbb" using 65 as key
expected "ciphertext: on...", not "onesbbn"
:( encrypts "world, say hello!" as "iadxp, emk tqxxa!" using 12 as key
expected "ciphertext: ia...", not "iadxp, emk tqx..."
:) handles lack of argv[1]
:) handles non-numeric key
:) handles too many arguments
To see more detailed results g
Saroj Gautam is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.