如何解决用 C
我想用 C 语言为凯撒密码构建一个解码器。我现在的代码如下所示:
#include <stdio.h>
#include <string.h>
int main(){
char str[100];
int i;
printf("Please enter the message that you want to decrypt: \n\n");
fgets(str,100,stdin);
printf("Please enter the letter shift\n\n");
scanf("%d",&i);
switch (i) {
case 1:
for(i = 0; (i < 100 && str[i] != '\0'); i++)
str[i] = str[i] - 15;
break;
default:
printf("\nError\n");
break;
}
printf("The decoded message is: \n\n");
printf("%s\n\n",str);
return 0;
}
问题是:程序仍然给我发回加密消息。我可以做些什么来改进我的代码?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。