截至目前,我的替换密码程序似乎工作得非常好;但是,我仍然遇到了这个问题。
我必须打印下面的替换表,在加密之前必须将表打印到输出文件中:
实施例
a m
b n
等...
z q
A P
B O
等...
Z X
0 5
1 4
等...
9 0
/ 在此加密消息 /
CODE:
#include <stdio.h>
char input[]={'\n',' ','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','0','1','2','3','4','5','6','7','8','9'};
char encrypted[]={'\n',' ','m','n','b','v','c','x','z','a','s','d','f','g','h','j','k','l','p','o','i','u','y','t','r','e','w','q','P','O','I','U','Y','T','R','E','W','Q','A','S','D','F','G','H','J','K','L','M','N','B','V','C','X','Z','5','4','3','2','1','6','7','8','9','0'};
int c;
//int j=0;
int main(){
FILE *file1=fopen("projectinput.txt", "r");
FILE *file2=fopen("projectoutput.txt", "w");
//fprintf(file2,"%c %c\n",input[j++],encrypted[j++]);
while((c=fgetc(file1))!=EOF){
int i=0;
while(input[i]!=c){
i++;
}
fputc(encrypted[i], file2);
}
return 0;
}
答案 0 :(得分:2)
在循环中使用fprintf
:
for(int i = 2; i < sizeof input; i++)
fprintf(file "%c %c\n", input[i], encrypted[i]);