user-0 提问: 凯撒密码出现的问题

回复:
user: user-0
content: 感谢楼上所有的回复，问题已经解决了，小白感谢大佬们

user: user-1
content: 注意,把infile outfile在打开文件的地方将其的双引号去掉,因为infile和outfile是字符数组,输入字符串后在打开时不需要在加上双引号；

user: user-1
content: #include<stdio.h> #include<stdlib.h> #include<windows.h> char encrypt(char ch,int n)/*加密函数，把字符向右循环移位n*/ { while(ch>='A'&&ch<='Z') {   return ('A'+(ch-'A'+n)%26); } while(ch>='a'&&ch<='z') {   return ('a'+(ch-'a'+n)%26); } return ch; } void menu()/*菜单，1.加密，2.解密，3.暴力破解，密码只能是数字*/ { system("cls"); printf("\n========================================================="); printf("\n1.Encrypt the file"); printf("\n2.Decrypt the file"); printf("\n3.Force decrypt file"); printf("\n4.Quit\n"); printf("=========================================================\n"); printf("Please select a item:"); return; } main() { int i,n; char ch0,ch1; FILE *in,*out; char infile[20],outfile[20]; system("cls"); Sleep(3);/*等待3秒*/ menu(); ch0=getchar(); while(ch0!='4') {   if(ch0=='1')   {   system("cls");/*清屏*/   printf("\nPlease input the infile:");   scanf("%s",infile);/*输入需要加密的文件名*/   if((in=fopen("infile","r"))==NULL) /*注意此处*/   {   printf("Can not open the infile!\n");           printf("Press any key to exit!\n");           getchar();           exit(0);   }   printf("Please input the key:");   scanf("%d",&n);/*输入加密密码*/    printf("Please input the outfile:");    scanf("%s",outfile);/*输入加密后文件的文件名*/    if((out=fopen("outfile","w"))==NULL) /*注意此处*/    {     printf("Can not open the outfile!\n");     printf("Press any key to exit!\n");     fclose(in);     getchar();     exit(0);    }    while(!feof(in))/*加密*/    {     fputc(encrypt(fgetc(in),n),out);/*如果in文件可以继续读取数据.                                        那么                                        fputc(fgetc(in),out)                                        读取in文件的一个字符然后文件指针in后移一个char长度,                                        然后输出到out文件中out文件指针后移一个char长度.*/    }    printf("\nEncrypt is over!\n");    fclose(in);    fclose(out);    Sleep(1);   }   if(ch0=='2')   {   system("cls");       printf("\nPlease input the infile:");       scanf("%s",infile);/*输入需要解密的文件名*/       if((in=fopen("infile","r"))==NULL)    /*注意此处*/    {     printf("Can not open the infile!\n");     printf("Press any key to exit!\n");     getchar();     exit(0);    }    printf("Please input the key:");    scanf("%d",&n);/*输入解密密码（可以为加密时候的密码）*/    n=26-n;    printf("Please input the outfile:");    scanf("%s",outfile);/*输入解密后文件的文件名*/    if((out=fopen("outfile","w")) == NULL)  /*注意此处*/    {     printf("Can not open the outfile!\n");     printf("Press any key to exit!\n");     fclose(in);     getchar();     exit(0);    }    while(!feof(in))    {     fputc(encrypt(fgetc(in),n),out);    }    printf("\nDecrypt is over!\n");    fclose(in);    fclose(out);    Sleep(1);   }   if(ch0=='3')   {    system("cls");    printf("\nPlease input the infile:");    scanf("%s",infile);/*输入需要解密的文件名*/    if((in=fopen("infile","r")) == NULL)   /*注意此处*/    {     printf("Can not open the infile!\n");     printf("Press any key to exit!\n");     getchar();     exit(0);    }    printf("Please input the outfile:");    scanf("%s",outfile);/*输入解密后文件的文件名*/    if((out=fopen("outfile","w")) == NULL)    /*注意此处*/    {     printf("Can not open the outfile!\n");     printf("Press any key to exit!\n");     fclose(in);     getchar();     exit(0);    }    for(i=1;i<=25;i++)/*暴力破解过程，在察看信息正确后，可以按'Q'或者'q'退出*/    {     rewind(in);     rewind(out);     system("cls");     printf("==========================================================\n");     printf("The outfile is:\n");     printf("==========================================================\n");     while(!feof(in))     {      ch1=encrypt(fgetc(in),26-i);      putchar(ch1);      fputc(ch1,out);     }     printf("\n========================================================\n");     printf("The current key is: %d \n",i);/*显示当前破解所用密码*/     printf("Press 'Q' to quit and other key to continue......\n");     printf("==========================================================\n");     ch1=getchar();     if(ch1=='q'||ch1=='Q')/*按'Q'或者'q'时退出*/     {      system("cls");      printf("\nGood Bye!\n");      fclose(in);      fclose(out);      Sleep(3);      exit(0);     }    }    printf("\nForce decrypt is over!\n");    fclose(in);    fclose(out);    Sleep(1);   }   menu();   ch0=getchar(); } system("cls");         printf("\nGood Bye!\n"); Sleep(3); return 0; }    注意你打开文件处的错误

user: user-2
content: 代码功能归根结底不是别人帮自己看或讲解或注释出来的；而是被自己静下心来花足够长的时间和精力亲自动手单步或设断点或对执行到某步获得的中间结果显示或写到日志文件中一步一步分析出来的。 提醒：再牛×的老师也无法代替学生自己领悟和上厕所！ 单步调试和设断点调试（VS IDE中编译连接通过以后，按F10或F11键单步执行，按Shift+F11退出当前函数；在某行按F9设断点后按F5执行停在该断点处。）是程序员必须掌握的技能之一。