我已经盯着这个问题好几个星期了,我什么都没有!它不起作用,我知道这么多,但我不知道为什么或出了什么问题。我确实知道开发人员针对我突出显示的行吐出了“错误:预期的表达式”,但实际上这只是冰山一角。如果有人知道如何修复任何一小部分,我将不胜感激!!!!!!!
好的,所以我更改了 i < n 和 >= 就像您建议的出色助手一样,它将贯穿并创建,但是仍然存在导致这些难看错误的故障:
:( encrypts "a" as "b" using 1 as key
\ expected output, not an exit code of 0
:( encrypts "barfoo" as "yxocll" using 23 as key
\ expected output, not an exit code of 0
:( encrypts "BARFOO" as "EDUIRR" using 3 as key
\ expected output, but not "E\nA\nU\nI\nR\nR\n"
:( encrypts "BaRFoo" as "FeVJss" using 4 as key
有什么建议么?
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <cs50.h>
#include <ctype.h>
int main(int argc, char *argv[])
{
//Get the key
if (argc != 2 || atoi(argv[1]) < 0)
{
printf("Usage: ./caesar k");
return 1;
}
int key = atoi(argv[1]);
string plaintext = GetString();
for (int i = 0, n = strlen(plaintext); i < n; i++)
{
if (plaintext[i] > 'A' && plaintext[i] <= 'Z')
{
plaintext[i] = (plaintext[i] - 'A' + key) % 26 + 'A';
}
}
for (int i = 0, n = strlen(plaintext); i < n; i++)
{
if (plaintext[i] >= 'A' && plaintext[i] >= 'Z')
{
plaintext[i] = (plaintext[i] - 'A' + key) % 26 + 'A';
}
else if (plaintext[i] >= 'a' && plaintext[i] < 'z')
{
plaintext[i] = (plaintext[i] - 'a' + key) % 26 + 'a';
}
else
{
printf("%c\n", plaintext[i]);
}
}
return 0;
}