【发布时间】:2021-12-20 20:32:30
【问题描述】:
当我运行 check50 时,我得到了这个:
:) caesar.c exists.
:) caesar.c compiles.
:) encrypts "a" as "b" using 1 as key
:( encrypts "barfoo" as "yxocll" using 23 as key
output not valid ASCII text
:) encrypts "BARFOO" as "EDUIRR" using 3 as key
:) encrypts "BaRFoo" as "FeVJss" using 4 as key
:( encrypts "barfoo" as "onesbb" using 65 as key
output not valid ASCII text
:( encrypts "world, say hello!" as "iadxp, emk tqxxa!" using 12 as key
output not valid ASCII text
:) handles lack of argv[1]
:) handles non-numeric key
:) handles too many arguments
我不确定“无效的 ASCII 文本”是什么意思或错误是什么。当我运行我得到“错误”的问题时,我在终端中得到了正确的输出,但 check50 将其标记为错误。
#include <stdlib.h>
#include <ctype.h>
#include <stdio.h>
#include <cs50.h>
#include <string.h>
#include <math.h>
int main(int argc, string argv[])
{
if (argc != 2)
{
return 1;
}
string bob=argv[1];
int lower_letters[]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
int upper_letters[]={'A', 'B', 'C', 'D', 'E','F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};
for (int e=0; e<strlen(bob); e++)
{
for (int g=0; g<26; g++)
{
if ((bob[e])==(lower_letters[g]))
{
printf("do not enter something that is not a number \n");
return 1;
}
}
}
int total = atoi(argv[1]);
if (total<0)
{
printf("do not input something that is a negative value\n");
return 1;
}
string word1 =get_string("plaintext: ");
printf("ciphertext: ");
for (int i =0; i<strlen(word1); i++)
{
if ((word1[i]==' ') || (word1[i]==',') || (word1[i]=='.') || (word1[i]=='!'))
{
printf("%c",word1[i]);
}
for (int a =0; a<26; a++)
{
if ((word1[i]==lower_letters[a]) && (a+total>26))
{
printf("%c",lower_letters[(a+total)-26]);
}
if (word1[i]==lower_letters[a])
{
printf("%c",lower_letters[a+total]);
}
if ((word1[i]==upper_letters[a]) && (a+total>26))
{
printf("%c",upper_letters[(a+total)-26]);
}
if (word1[i]==upper_letters[a])
{
printf("%c",upper_letters[a+total]);
}
}
}
printf("\n");
}
能否请我帮忙解决“无效的 ASCII 文本”错误?
【问题讨论】: