| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 413 人关注过本帖
标题:C语言请教`这代码运行不了`
只看楼主 加入收藏
fyong011
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2010-3-22
结帖率:0
收藏
已结贴  问题点数:20 回复次数:5 
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();
}
}
搜索更多相关主题的帖子: 运行 代码 C语言 
2010-03-22 22:51
cnfarer
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:179
帖 子:3330
专家分:21157
注 册:2010-1-19
收藏
得分:6 
用TC2.0编译,可以运行!用VC编译器的话,需要作适当修改.

★★★★★为人民服务★★★★★
2010-03-23 14:35
fyong011
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2010-3-22
收藏
得分:0 
回复 2楼 cnfarer
那要怎么修改呢
2010-03-24 12:33
qq978429788
Rank: 2
等 级:论坛游民
帖 子:7
专家分:28
注 册:2010-2-26
收藏
得分:6 
函数名: textbackground
  功 能: 选择新的文本背景颜色
  用 法: void textbackground(int color);
  头文件: 包含在conio.h头文件中,但是在vc的conio.h中找不到这个函数,TC中有;
2010-03-25 20:16
wei0000
Rank: 3Rank: 3
等 级:论坛游侠
威 望:1
帖 子:80
专家分:136
注 册:2010-3-12
收藏
得分:6 
我怎么没看到c语言中有关于楼主写的那些函数,谁能告诉那些是用来干什么的,谁能上传些关于那样的资料给我,万盛感激!!!!!!!!!!!!
2010-03-26 21:28
wei0000
Rank: 3Rank: 3
等 级:论坛游侠
威 望:1
帖 子:80
专家分:136
注 册:2010-3-12
收藏
得分:0 
我想学习学习啊
2010-03-26 21:30
快速回复:C语言请教`这代码运行不了`
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.014728 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved