请问我编的这个程序出了神马状况????

系统安装、升级讨论
版面规则
我们都知道新人的确很菜,也喜欢抱怨,并且带有浓厚的Windows习惯,但既然在这里询问,我们就应该有责任帮助他们解决问题,而不是直接泼冷水、简单的否定或发表对解决问题没有任何帮助的帖子。乐于分享,以人为本,这正是Ubuntu的精神所在。
头像
cuihao
帖子: 4793
注册时间: 2008-07-24 11:33
来自: 郑州
联系:

Re: 请问我编的这个程序出了神马状况????

#16

帖子 cuihao » 2011-01-08 22:25

给你一个头文件的示例:

代码: 全选

#ifndef _LOCK_HEADER
#define _LOCK_HEADER

void unlock(char rin[],char passwd[]);
void out(char rin[]);
void lock(char rin[],char passwd[]);
int jin(int max);

#endif /* _LOCK_HEADER */
不要include"xxx.cpp",include这个头文件。
求人不如求它仨: 天蓝的Wiki 屎黄的Wiki 绿
Site: CUIHAO.TK    Twitter: @cuihaoleo
Machine: Athlon64 X2 5200+ / 2x2GB DDR2-800 / GeForce GTS 450
AD: ~まだ見ぬ誰かの笑顔のために~
头像
mopperwhite
帖子: 330
注册时间: 2010-05-02 20:25
来自: 柯伊伯带外奥尔特云内轨道与黄道错开的空间站里

Re: 请问我编的这个程序出了神马状况????

#17

帖子 mopperwhite » 2011-01-09 19:11

cuihao 写了:给你一个头文件的示例:

代码: 全选

#ifndef _LOCK_HEADER
#define _LOCK_HEADER

void unlock(char rin[],char passwd[]);
void out(char rin[]);
void lock(char rin[],char passwd[]);
int jin(int max);

#endif /* _LOCK_HEADER */
不要include"xxx.cpp",include这个头文件。
谢啦!昨晚有个人帮我改了下代码!就是这样!
drazet帮忙的,谢谢了!
jiami.tar.gz
加密bate0.02
(6.77 KiB) 已下载 26 次
愿他们残酷,但是永远正义
愿恐惧永远不会主宰他们的行动并愿民族的荣誉在他们心中高于一切
最后,愿他们最终可以理解,为完成我们建立民族社会主义国家的任务,需要数百年时间并需要每一个人永远将共同的利益置于个人利益之上。
----希特勒绝笔
讨厌我的人可以试着点一下
讨厌我的人可以试着点一下2.0bate
头像
mopperwhite
帖子: 330
注册时间: 2010-05-02 20:25
来自: 柯伊伯带外奥尔特云内轨道与黄道错开的空间站里

Re: 请问我编的这个程序出了神马状况????

#18

帖子 mopperwhite » 2011-01-09 19:15

然后自己修正了几个BUG合成一个bate0.03

代码: 全选

//		MopperWhite的加密软件 bate 0.03
//		请编辑过这个文档的人在文档末端留下您的大名及大致解决的问题或增加的功能作为日志!!别忘了标日期!!!
// 
//      加密bate0.03.c
//      
//      Copyright 2011 MopperWhite email:mopperwhite@gmail.com
//      
//      This program is free software; you can redistribute it and/or modify
//      it under the terms of the GNU General Public License as published by
//      the Free Software Foundation; either version 2 of the License, or
//      (at your option) any later version.
//      
//      This program is distributed in the hope that it will be useful,
//      but WITHOUT ANY WARRANTY; without even the implied warranty of
//      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//      GNU General Public License for more details.
//      
//      You should have received a copy of the GNU General Public License
//      along with this program; if not, write to the Free Software
//      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
//      MA 02110-1301, USA.
//      This program is free software; you can redistribute it and/or modify
//      it under the terms of the GNU General Public License as published by
//      the Free Software Foundation; either version 2 of the License, or
//      (at your option) any later version.
//      
//      This program is distributed in the hope that it will be useful,
//      but WITHOUT ANY WARRANTY; without even the implied warranty of
//      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//      GNU General Public License for more details.
//      
//      You should have received a copy of the GNU General Public License
//      along with this program; if not, write to the Free Software
//      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
//      MA 02110-1301, USA.


#include <stdio.h>
#include <string.h>
#define MAXN 1000000
int myin()
{
	char i;
	printf("本软件暂时不能识别换行(俗称回车),请一段一段进行\n本软件能读取的内容长度仅限于%d个字节(%d个汉字)'\n由于算法不同,本软件能解密同一软件加密的数据,当然,您可以自己修改它的源码来更改算法 XD\n",MAXN,MAXN/2);
	printf("请问您想加密文件还是解密文件?\n若加密请输“l”,解密请输“u”,退出请输入“e”\nYou:");
	scanf("%c",&i);
	if(i=='l') return 1;
	else
		if(i=='u') return 2;
		else
			if(i=='e') return 3;
			else
				{
					printf("请再看看上面的提示!!\n");
					return myin();
				}
	return 0;
}
void myout(char *rin)
{
	char w;//结束时延迟用
	printf("以下为处理结果:\n%s",rin);
	printf("\n\n========================我是分割线~=========================\n为了防止终端无法显示输出字符,结果将在软件关闭后被存储在当前目录下“mout.txt”文件中\n最后说一下,本软件是开源软件,理论上您应该可以从装它的压缩包里找到源代码\n友情提示:OGC伤身体(不要深究它的意思……)\n感谢您的使用~~~~~  XD\n按回车即可退出");
	scanf("%c",&w);
	freopen("./mout.txt","w",stdout);
	printf("%s",rin);
}
void lock(char *rin,char *passwd)
{
	int n=strlen(rin);
	int m=strlen(passwd);
	int i,j=0;
	for(i=0;i<n;i++,j++)
	{
		rin[i]=rin[i]+passwd[j]-43;
		if(j>=m-1) j=-1;
	}
	myout(rin);
}
void unlock(char rin[],char passwd[])
{
	int n=strlen(rin);
	int m=strlen(passwd);
	int i,j=0;
	for(i=0;i<n;i++,j++)
	{
		rin[i]=rin[i]-passwd[j]+43;
		if(j>=m-1) j=-1;
	}
	myout(rin);
}
int main(void)
{
	printf("*************************************************\n本软件使用GPL协议发布,您可以随意更改、复制、使用它的源代码\n*************************************************\n\n");
	char _b[10];
	char rin[MAXN];
	char passwd[MAXN];
	int jinn=myin();
	//printf("%d",myin());
	if(jinn==1) sprintf(_b,"%s","加密");
	else
		if(jinn==2) sprintf(_b,"%s","解密");
		else
			if(jinn==3) return 0;
			else
			{
				printf("起始模块发生未知错误");
				return 0;
			}
	printf("请输入您要%s的内容,输完请按回车:\n",_b);
	scanf("%s",rin);
	//gets(rin);
	/*int i=0;
	char c;
    while((c!='\0')&&(c!='\n'))
    {
		scanf("%c",&c);
		rin[i++]=c;
	}*/
	//上面被注释掉的部分是为了解决输入不能带空格而写的——很明显,它失败了
	printf("密码中禁止空格!\n请输入密码:");
	//gets(passwd);
    scanf("%s",passwd);
	if(jinn==1) lock(rin,passwd);
	if(jinn==2) unlock(rin,passwd);
	return 0;
}
//软件生来自由!!!!!!!!
//坚定GPL一百年不动摇!!!!

//下面是日志:
//====================Bate0.02===========================================
//备注:0.02版本经过Drazet童鞋的修改与优化,谨此表达感谢!
//同时对MW的编程水平……不发表任何意见……
//重要修正:Drazet童鞋帮助解决了MW的把C存成.cpp的问题以及if后的缩进等不良习惯,同时解决了out函数不能通过编译的问题【要命的*.h啊!!!】
//还有!in和out貌似是被占用的!!
//2011/01/08
//====================Bate0.03==========================================
//MopperWhite将0.02中Drazet优化和修改的部分放进同一个文件= =#(原因么……因为MW不会写*.h……)
//貌似难度不大- -!
//纠正一个错别字~
//修正了一个因为if和else使用不当造成异常退出的BUG
//在注释中要求后面的修改者(别看了,就是你!)写日志~
//增加了文件输出(无效~)
//输入不能有空格的BUG待解决
//今天搞不定中文无法解密的问题,建议用if语句对ASCLL码较大的字符进行特殊处理(>100)
//2011/01/09
愿他们残酷,但是永远正义
愿恐惧永远不会主宰他们的行动并愿民族的荣誉在他们心中高于一切
最后,愿他们最终可以理解,为完成我们建立民族社会主义国家的任务,需要数百年时间并需要每一个人永远将共同的利益置于个人利益之上。
----希特勒绝笔
讨厌我的人可以试着点一下
讨厌我的人可以试着点一下2.0bate
头像
mopperwhite
帖子: 330
注册时间: 2010-05-02 20:25
来自: 柯伊伯带外奥尔特云内轨道与黄道错开的空间站里

Re: 请问我编的这个程序出了神马状况????

#19

帖子 mopperwhite » 2011-01-09 19:20

自己弄了个加密文件功能弄成bate0.04
改掉几个BUG
输出怪怪的
对文件很不熟……

代码: 全选

//		MopperWhite的加密软件 bate 0.03
//		请编辑过这个文档的人在文档末端留下您的大名及大致解决的问题或增加的功能作为日志!!别忘了标日期!!!
// 
//      加密bate0.04.c
//      
//      Copyright 2011 MopperWhite email:mopperwhite@gmail.com
//      
//      This program is free software; you can redistribute it and/or modify
//      it under the terms of the GNU General Public License as published by
//      the Free Software Foundation; either version 2 of the License, or
//      (at your option) any later version.
//      
//      This program is distributed in the hope that it will be useful,
//      but WITHOUT ANY WARRANTY; without even the implied warranty of
//      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//      GNU General Public License for more details.
//      
//      You should have received a copy of the GNU General Public License
//      along with this program; if not, write to the Free Software
//      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
//      MA 02110-1301, USA.
//      This program is free software; you can redistribute it and/or modify
//      it under the terms of the GNU General Public License as published by
//      the Free Software Foundation; either version 2 of the License, or
//      (at your option) any later version.
//      
//      This program is distributed in the hope that it will be useful,
//      but WITHOUT ANY WARRANTY; without even the implied warranty of
//      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//      GNU General Public License for more details.
//      
//      You should have received a copy of the GNU General Public License
//      along with this program; if not, write to the Free Software
//      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
//      MA 02110-1301, USA.


#include <stdio.h>
#include <string.h>
#define MAXN 1000000
int myin()
{
	char i;
	printf("本软件暂时不能识别换行(俗称回车)与空格\n本软件能读取的内容长度仅限于%d个字节(%d个汉字)'\n由于算法不同,本软件能解密同一软件加密的数据,当然,您可以自己修改它的源码来更改算法 XD\n",MAXN,MAXN/2);
	printf("请问您想加密文件还是解密文件?\n若加密请输“l”,解密请输“u”,退出请输入“e”\nYou:");
	scanf("%c",&i);
	if(i=='l') return 1;
	else
		if(i=='u') return 2;
		else
			if(i=='e') return 3;
			else
				{
					printf("请再看看上面的提示!!\n");
					return myin();
				}
	return 0;
}
void lock(char *rin,char *passwd,char *filename)
{
	int n=strlen(rin);
	int m=strlen(passwd);
	int i,j=0;
	for(i=0;i<n;i++,j++)
	{
		rin[i]=rin[i]+passwd[j]-43;
		if(j>=m-1) j=-1;
	}
	sprintf(filename,"%s%s",filename,".mout");
	freopen(filename,"w",stdout);
	printf("%s",rin);
}
void unlock(char *rin,char *passwd,char *filename)
{
	int n=strlen(rin);
	int m=strlen(passwd);
	int o=strlen(filename);
	char _filename[MAXN];
	int i,j=0;
	for(i=0;i<o-5;i++)
		_filename[i]=filename[i];
	for(i=0;i<n;i++,j++)
	{
		rin[i]=rin[i]-passwd[j]+43;
		if(j>=m-1) j=-1;
	}
	freopen(_filename,"w",stdout);
	printf("%s",rin);
}
void myout(char *filename,char *passwd,int jinn)
{
	//char c;
	char rin[MAXN];
	//printf("以下为处理结果:\n%s",rin);
	printf("\n\n========================我是分割线~=========================\n处理完毕的文件将在软件关闭后被存储在当前目录下\n最后说一下,本软件是开源软件,理论上您应该可以从装它的压缩包里找到源代码\n感谢您的使用~~~~~  XD\n");
	//scanf("%c",&c);
	sprintf(filename,"%s%s","./",filename);
	freopen(filename,"r",stdin);
	/*do
	{
		scanf("%c",&c);
		sprintf(rin,"%s%c",rin,c);
	}while(c!='\0');*/
	//gets(rin);
	scanf("%s",rin);
	if(jinn==1) lock(rin,passwd,filename);
	if(jinn==2) unlock(rin,passwd,filename);
}
int main(void)
{
	printf("***********************************************************\n本软件使用GPL协议发布,您可以随意更改、复制、使用它的源代码\n***********************************************************\n\n");
	char _b[10];
	//char rin[MAXN];
	char filename[MAXN];
	char passwd[MAXN];
	int jinn=myin();
	//printf("%d",myin());
	if(jinn==1) sprintf(_b,"%s","加密");
	else
		if(jinn==2) sprintf(_b,"%s","解密");
		else
			if(jinn==3) return 0;
			else
			{
				printf("起始模块发生未知错误");
				return 0;
			}
	printf("请输入您将要%s的文件放在本软件的运行目录下并输入文件名,输完请按回车:\n",_b);
	scanf("%s",filename);
	printf("请输入密码:");
	//gets(passwd);
    scanf("%s",passwd);
    myout(filename,passwd,jinn);
	//if(jinn==1) lock(rin,passwd);
	//if(jinn==2) unlock(rin,passwd);
	return 0;
}
//软件生来自由!!!!!!!!
//坚定GPL一百年不动摇!!!!

//下面是日志:
//====================Bate0.02===========================================
//备注:0.02版本经过Drazet童鞋的修改与优化,谨此表达感谢!
//同时对MW的编程水平……不发表任何意见……
//重要修正:Drazet童鞋帮助解决了MW的把C存成.cpp的问题以及if后的缩进等不良习惯,同时解决了out函数不能通过编译的问题【要命的*.h啊!!!】
//还有!in和out貌似是被占用的!!
//2011/01/08
//====================Bate0.03==========================================
//MopperWhite将0.02中Drazet优化和修改的部分放进同一个文件= =#(原因么……因为MW不会写*.h……)
//貌似难度不大- -!
//纠正一个错别字~
//修正了一个因为if和else使用不当造成异常退出的BUG
//在注释中要求后面的修改者(别看了,就是你!)写日志~
//增加了文件输出(无效~)
//输入不能有空格的BUG待解决
//今天搞不定中文无法解密的问题,建议用if语句对ASCLL码较大的字符进行特殊处理(>100)
//2011/01/09
//====================Bate0.04====================================
//修改为加密文件
//回车问题依旧……
//把“\n友情提示:OGC伤身体(不要深究它的意思……)”去掉……"OGC"本身很邪恶……
//2011/01/09
愿他们残酷,但是永远正义
愿恐惧永远不会主宰他们的行动并愿民族的荣誉在他们心中高于一切
最后,愿他们最终可以理解,为完成我们建立民族社会主义国家的任务,需要数百年时间并需要每一个人永远将共同的利益置于个人利益之上。
----希特勒绝笔
讨厌我的人可以试着点一下
讨厌我的人可以试着点一下2.0bate
头像
liu滔
帖子: 7212
注册时间: 2010-10-09 23:01

Re: 请问我编的这个程序出了神马状况????

#20

帖子 liu滔 » 2011-01-09 23:05

upsuper 写了:
cuihao 写了:
mopperwhite 写了:
cuihao 写了:LZ应该写标准的程序。

你的程序完全就是C语言的,却要cpp扩展名。
只有C++才能拆成几分
老师说我应该习惯存成cpp……
:em06 你们老师没搞错把,谁说只有C++才能拆分?
看看GTK,全用C写的.
Linux Kernel 还是C和汇编写的……不能拆分的话实在难以想像那个文件的大小……
不会拆成几个.c文件,所以我一直以来都是只写一个大文件的——其实也不大~ :em03
回复