gpt4 book ai didi

凯撒密码 C 语言

转载 作者:行者123 更新时间:2023-11-30 17:38:54 29 4
gpt4 key购买 nike

我已经盯着这个问题好几个星期了,但我一无所获!它不起作用,我知道那么多,但我不知道为什么或出了什么问题。我确实知道开发人员针对我突出显示的行吐出了“错误:预期表达式”,但这实际上只是冰山一角。如果有人知道如何修复其中的任何一小部分,我将不胜感激!!!!

好吧,我改变了 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;
}

最佳答案

更改您的以下行

if (plaintext[i] => 'A' && plaintext[i] >= 'Z')

if (plaintext[i] >= 'A' && plaintext[i] >= 'Z')

您应该使用 >= 而不是 =>

关于凯撒密码 C 语言,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22004892/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com