C语言请教`这代码运行不了`
#include<stdio.h>
#include<conio.h>
void menu()/*菜单,1.加密 2.解密 3.退出*/
{
clrscr();
printf("\n===============================================================================");
printf("\n1.Encrypt the file");
printf("\n2.Decrypt the file");
printf("\n3.Quit\n");
printf("===============================================================================\n");
printf("Please select a item:");
return;
}
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;
}
main()
{
int i,n;
char ch0,ch1;
FILE *in,*out;
char infile[10],outfile[10];
textbackground(RED);
textcolor(LIGHTGREEN);
clrscr();
menu();
ch0=getch();
while(ch0!='3')
{
if(ch0=='1')
{
clrscr();
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");
getch();
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);
getch();
exit(0);
}
while(!feof(in))/*加密*/
{
fputc(encrypt(fgetc(in),n),out);
}
printf("\nEncrypt is over!\n");
fclose(in);
fclose(out);
sleep(1);
}
if(ch0=='2')
{
clrscr();
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");
getch();
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);
getch();
exit(0);
}
while(!feof(in))
{
fputc(encrypt(fgetc(in),n),out);
}
printf("\nDecrypt is over!\n");
fclose(in);
fclose(out);
sleep(1);
}
clrscr();
printf("\nGood Bye!\n");
sleep(3);
getch();
}
}