gpt4 book ai didi

c - 在 Main 之外操作数组

转载 作者:太空宇宙 更新时间:2023-11-04 07:05:39 25 4
gpt4 key购买 nike

<分区>

我正在尝试编写一个简单的加密程序(凯撒密码),但遇到了麻烦。我对 C 和指针的世界比较陌生,最初来自 Java。

每当我运行以下代码时,它都会给我错误消息 Segmentation fault 并终止。

我已经阅读了一些关于这意味着什么的内容,但我仍然没有完全理解它,或者我的代码有什么问题,或者如何解决这个问题。

如果您能提供任何帮助,我们将不胜感激。

#include <stdio.h>
#include <ctype.h>
#include <string.h>

void encrypt(char *input);

int main()
{
char *instructions = "pipi";

encrypt(instructions);

printf("Here are your secret instructions:\n%s\n", instructions);

return (0);
}

void encrypt(char *input) {
while (*input != '\0') {
if (isalpha(*input)) {
*input += 1;
if (!isalpha(*input)) {
*input -= 26;
}
}
input++;
}
}

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