我的 caesar.c 文件中的代码
#include <stdio.h>
#include <cs50.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
int main(int argc, string argv[])
{
// get a string from the user, a non-negative integer.
if (argc != 2 || atoi(argv[0]) < 0)
{
printf("Usage: ./caesar cyphertext\n");
return 1;
}
// create the cyphertext.
int cyphertext = atoi(argv[1]);
// declare plaintext input.
string plaintext = GetString();
// get the plaintext encrypted using the key.
for (int i = 0, n = strlen(plaintext); i < n; i++)
{
if (plaintext[i] > 'A' && plaintext[i] <= 'Z')
{
plaintext[i] = (plaintext[i] - 'A' + cyphertext) % 26;
}
else if (plaintext[i] >= 'a' && plaintext[i] < 'z')
{
plaintext[i] = (plaintext[i] - 'a' + cyphertext) % 26;
}
}
{
// print out the results of the cypher and plaintext.
printf("%s\n", plaintext);
}
return 0;
}
输出我输入,./caesar 13
然后在下一行输入单词“hello”。Hello 然后返回几个小盒子,里面有小写字母和数字。我无法复制和粘贴确切的字符。
编辑:
谢谢您的帮助。我根据您的帮助进行了清理,现在当我运行 check50 程序时
check50 2014/x/pset2/caesar caesar.c
我收到以下错误:
:( encrypts "BARFOO" as "EDUIRR" using 3 as key
\ expected output, but not "EAUIRR\n"
然而,当我以 3 作为键运行单词 BARFOO 时,实际上我得到的输出是 EAUIRR。