C++ 有人能告诉我怎么做吗?
我编写了一个程序,可以读取和打印用户选择的文本文件。我现在希望该程序加密文件中的文本,并为用户能够选择字母移位。有人能告诉我怎么做吗?以下是我到目前为止的情况:C++ 有人能告诉我怎么做吗?,c++,visual-studio-2010,C++,Visual Studio 2010,我编写了一个程序,可以读取和打印用户选择的文本文件。我现在希望该程序加密文件中的文本,并为用户能够选择字母移位。有人能告诉我怎么做吗?以下是我到目前为止的情况: #include <stdio.h> int main(void) { FILE *file_in; char filename[20]; char ch; int shift; // file_in is the name given to the stream. filename
#include <stdio.h>
int main(void) {
FILE *file_in;
char filename[20];
char ch;
int shift;
// file_in is the name given to the stream. filename will be the file that the user chooses. ch is the characters in the file.
printf("What file do you want to open?: ");
gets(filename);
file_in=fopen(filename, "r");
//ask the user to enter the name of a file
if(file_in==NULL)
printf("Error! File did not open.\n");
//print message if the file can not be found
while((ch=fgetc(file_in)) != EOF)
putchar(ch);
//prints the results on the screen and shows the end of the file
fclose(file_in);
//closes stream
}`enter code here`
#包括
内部主(空){
文件*FILE_in;
字符文件名[20];
char ch;
int移位;
//file_in是流的名称。filename是用户选择的文件。ch是文件中的字符。
printf(“要打开什么文件?”:”;
获取(文件名);
file_in=fopen(文件名,“r”);
//要求用户输入文件名
if(file_in==NULL)
printf(“错误!文件未打开。\n”);
//如果找不到文件,则打印消息
while((ch=fgetc(file_in))!=EOF)
putchar(ch);
//在屏幕上打印结果并显示文件的结尾
fclose(文件输入);
//断流
}`在这里输入代码`
对于简单的字母移位,将移位存储为字符
,并像userinput中的文件名一样读取它。替换putchar(ch)代码>通过putchar(ch+shift)
用于加密,ch shift用于解密或vv<如果总和大于char
的最大值,则code>ch+shift
将自动溢出,从而保证每个字母ch
都有一个“加密”对应项。一般来说,除了编程练习之外,不要自己编写加密代码。依赖经过良好测试的开源代码。