到目前为止,这是我的代码:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void railFence(char *message, char *cipherText, int length, int A);
void railFence2(char *message, char *cipherText, int length, int A, int B);
int main() {
char output[1024], input[1024];
int choice, keyA, keyB, arrayLength;
printf("Cypher Program\n");
printf("--------------\n");
printf("Enter a number to choose a cypher program:\n");
printf("(1)1 Level Railfence\n(2)2 Level Railfence\n(3)Substitution Decrypt\n\n");
scanf("%d", &choice);
system("cls");
switch(choice)
{
case 1: //1 level
printf("1 Level Railfence encryption/decryption:\n");
printf("----------------------------------------\n\n");
printf("Enter your message:\n");
scanf(" %[^*]", input);
arrayLength = strlen(input);
railFence(input, output, arrayLength, keyA);
printf("%s\n", output);
break;
case 2: //2 level
printf("2 Level Railfence encryption/decryption:\n");
printf("----------------------------------------\n");
break;
case 3: //Substitution cypher decription
break;
default:
printf("ERROR: %d is not a valid choice", choice);
return 0;
}
}
void railFence(char *message, char *cipherText, int length, int A){
char grid[length][A];
int rail, i = 0, j = 0, choice;
printf("Enter '1' for encryption or '2' for decription:\n");
scanf("%d", &choice);
switch(choice)
{
case 1:
break;
case 2:
break;
default:
printf("ERROR: %d is not a valid choice", choice);
return 0;
}
}
该代码处于早期阶段,但是我无法在railfence()函数中使用“切换用例”,因为某些时候变量“ choice”似乎已经设置为32766(我相信这是“ /”的值)原因和scanf()只是被跳过,甚至不要求用户输入。我已经搜索了大约一个半小时的解决方案,并尝试在过去对我有用的%d前面放置空格,我尝试更改变量名称并重新排序该函数。我不确定问题可能出在主要功能上。我有一个解决方案,但是它需要将更多的内容移到我要避免的主要功能中。 任何帮助,将不胜感激。