gpt4 book ai didi

c - 为 Ceasar's Code 在 C 中环绕

转载 作者:太空宇宙 更新时间:2023-11-04 01:29:50 24 4
gpt4 key购买 nike

嘿,伙计,我上次发帖有点草率。希望这次看起来会好很多。如果您决定帮助我,谢谢您的宝贵时间。我真的需要它。无论如何,这是问题。我需要为我的代码环绕,我听说你可以用模数来做,但我不确定我做的是否正确,因为我没有得到正确的结果。

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int main () {
char s[200]; //blank array//
int mess;
printf("Generations have wondered how the Ceasar Code works\n");
printf("Please choose a number to mess up (encode) the current file\n");
scanf("%d", &mess);
mess = mess % 26;
FILE *ptof = fopen("Rock.txt", "r");
char a[200];//fill array with characters from file//
int i=0;
while( (a[i++]=fgetc(ptof)) != EOF && i < 89) { //get character from file//
}
a[i] = '\0'; /* null-terminate the string */
i = 0;

do{
printf("%c",a[i++]);
} while (a[i] != '\0'); /* print until hit \0 */
int j = 0;
for (j = 0; j < 89; j++){
s[j] = a[j] + mess;
}
printf("%s\n", s);

fclose(ptof);
return 0;
}

最佳答案

s[j] = a[j] + mess 也需要模运算

关于c - 为 Ceasar's Code 在 C 中环绕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24439672/

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