在过去的几天里,我一直在进行cs50项目“ Caesar”的工作,并设法使它达到视觉输出的目的,但是,每当我运行该课程要求我运行的check50时,它似乎一直在我遇到了多个无法直接找到的错误,因为在查看视觉输出时似乎是预期的。
这是由于在cs50 IDE中工作并遵循以下项目链接而产生的:
https://cs50.harvard.edu/x/2020/psets/2/caesar/
这是cs50 check50函数给出的结果:
> :( encrypts "a" as "b" using 1 as key
> expected "ciphertext: b\...", not "ciphertext: b"
> Log
> running ./caesar 1...
> sending input a...
> checking for output "ciphertext: b\n"...
>
> Expected Output:
> ciphertext: b
> Actual Output:
> ciphertext: b
> :( encrypts "barfoo" as "yxocll" using 23 as key
> expected "ciphertext: yx...", not "ciphertext: yx..."
> Log
> running ./caesar 23...
> sending input barfoo...
> checking for output "ciphertext: yxocll\n"...
>
> Expected Output:
> ciphertext: yxocll
> Actual Output:
> ciphertext: yxocll
> :( encrypts "BARFOO" as "EDUIRR" using 3 as key
> expected "ciphertext: ED...", not "ciphertext: ED..."
> Log
> running ./caesar 3...
> sending input BARFOO...
> checking for output "ciphertext: EDUIRR\n"...
>
> Expected Output:
> ciphertext: EDUIRR
> Actual Output:
> ciphertext: EDUIRR
> :( encrypts "BaRFoo" as "FeVJss" using 4 as key
> expected "ciphertext: Fe...", not "ciphertext: Fe..."
> Log
> running ./caesar 4...
> sending input BaRFoo...
> checking for output "ciphertext: FeVJss\n"...
>
> Expected Output:
> ciphertext: FeVJss
> Actual Output:
> ciphertext: FeVJss
> :( encrypts "barfoo" as "onesbb" using 65 as key
> expected "ciphertext: on...", not "ciphertext: on..."
> Log
> running ./caesar 65...
> sending input barfoo...
> checking for output "ciphertext: onesbb\n"...
>
> Expected Output:
> ciphertext: onesbb
> Actual Output:
> ciphertext: onesbb
> :( encrypts "world, say hello!" as "iadxp, emk tqxxa!" using 12 as key
> expected "ciphertext: ia...", not "ciphertext: ia..."
> Log
> running ./caesar 12...
> sending input world, say hello!...
> checking for output "ciphertext: iadxp, emk tqxxa!\n"...
>
>
> <<
这是使用cs50库在C中完成的代码,以简化功能:
//string validity
if (validity)
{
//prompt for plaintext
string plaintext = get_string("Plaintext: ");
printf("ciphertext: ");
int n = strlen(plaintext);
//calculate the encryption
for (int i = 0; i < n; i++)
{
if (isupper(plaintext[i]))
{
printf("%c", (plaintext[i] - 'A' + KEY) % 26 + 'A');
}
else if (islower(plaintext[i]))
{
printf("%c", (plaintext[i] - 'a' + KEY) % 26 + 'a');
}
else if( ispunct(plaintext[i]) || isspace(plaintext[i]))
{
printf("%c", plaintext[i]);
}
}
return 0;
}
}
}
我相信问题出在上述代码的输出部分,我将非常感谢您的帮助
答案来自“一些程序员伙计”的评论
原来,我必须在输出中打印最后一个'\ n'才能使其工作100%
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句