程序的自我保护

cTx521 2009-07-03 04:00:06
/* 在BC31下编译 */
/* compile under Borland C++ 3.1 */

#include <dos.h>
#include <dir.h>
#include <stdio.h>
#include <io.h>
#include <sys\stat.h>

int main( int argc, char* argv[] )
{
struct time now;
FILE* fp;
int errno;
gettime( &now );
if( now.ti_min > 30 ) /*如非法使用系统则删除程序*/
{
errno = chmod( argv[0], S_IWRITE );
if((errno)&& ( fp != NULL ))
{
fclose( fp );
/*将文件长度截止为0*/
unlink( argv[0] );
exit(0);
/*然后删除本文件退出*/
}
else
{
/*如不能删除打印错误退出*/
printf( "\n You are a illegal user to run this program! \007\n" );
exit(1);
}
}
printf(" You are a legitimate user to run this program!\n");
getch();
return 0;
}






//书上看到的代码 但是运行出错 各位大侠帮忙给看看哈
...全文
152 19 打赏 收藏 转发到动态 举报
写回复
用AI写文章
19 条回复
切换为时间正序
请发表友善的回复…
发表回复
cTx521 2009-07-06
  • 打赏
  • 举报
回复
好嘛 我就看哈他思路
xempo 2009-07-06
  • 打赏
  • 举报
回复
[Quote=引用 16 楼 cTx521 的回复:]
人民邮电出版社的 C语言实例解析精粹(第二版)
[/Quote]我原想说:“这样的程序最好别理它,练习别的。”
guocai_yao 2009-07-04
  • 打赏
  • 举报
回复
[Quote=引用 12 楼 hecongjuan 的回复:]
time now 没有这个类型
gettime 不能够找到这个函数
exit 系统不认这个语句
[/Quote]
前两个加#include <stdio.h>试试
后一个加#inlcude <stdlib.h>试试
cTx521 2009-07-04
  • 打赏
  • 举报
回复
人民邮电出版社的 C语言实例解析精粹(第二版)
xempo 2009-07-04
  • 打赏
  • 举报
回复
我看,这个程序有很多的错误。哪本书上的?
cTx521 2009-07-04
  • 打赏
  • 举报
回复
[Quote=引用 13 楼 Fleeboy 的回复:]
BC31也太老旧了吧
[/Quote]

你们用的是??
Fleeboy 2009-07-03
  • 打赏
  • 举报
回复
BC31也太老旧了吧
天地一棵树 2009-07-03
  • 打赏
  • 举报
回复
time now 没有这个类型
gettime 不能够找到这个函数
exit 系统不认这个语句
cTx521 2009-07-03
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 supermegaboy 的回复:]
楼主的代码缺少time.h头文件。
[/Quote]加了这个文件 还是一样的
飞天御剑流 2009-07-03
  • 打赏
  • 举报
回复
楼主的代码缺少time.h头文件。
Arnold9009 2009-07-03
  • 打赏
  • 举报
回复
结构体time是未定义
gettime函数未定义

应该是缺少头文件吧
lzldnc 2009-07-03
  • 打赏
  • 举报
回复
time now 没有这个类型
gettime 不能够找到这个函数
exit 系统不认这个语句
cTx521 2009-07-03
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 zhijianqishen 的回复:]
错误信息输出来看看吧
[/Quote]

--------------------Configuration: a - Debug--------------------
Compiling...
a.cpp
a.cpp: In function `int main(int, char**)':
a.cpp:13: error: aggregate `time now' has incomplete type and cannot be defined
a.cpp:16: error: `gettime' undeclared (first use this function)
a.cpp:16: error: (Each undeclared identifier is reported only once for each
function it appears in.)
a.cpp:25: error: `exit' undeclared (first use this function)

a.o - 4 error(s), 0 warning(s)
Walf_ghoul 2009-07-03
  • 打赏
  • 举报
回复
没看出来。。。
mengjfu 2009-07-03
  • 打赏
  • 举报
回复
不知fp指向那?
zhijianqishen 2009-07-03
  • 打赏
  • 举报
回复
错误信息输出来看看吧
cTx521 2009-07-03
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 asksgp 的回复:]
要在运行的第一个参数输入文件名,你输入了吗?
[/Quote]
编译的时候就出错呀! ???
asksgp 2009-07-03
  • 打赏
  • 举报
回复
要在运行的第一个参数输入文件名,你输入了吗?
大前置 2009-07-03
  • 打赏
  • 举报
回复
没有编译环境,看不出来,帮你顶~~~

69,371

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧