C语言中的自毁代码

使用C语言中的remove()函数,我们可以编写一个程序,在编译和执行后可以销毁它自己。

null

说明: 这可以使用 移除函数 注意,这是在Linux环境中完成的。因此,remove函数被输入命令行参数中的第一个参数,即。 a、 出去 编译后创建的文件(可执行文件)。因此,该程序将被销毁。

// CPP program of self destructing output file
#include<stdio.h>
#include<stdlib.h>
int main( int c, char *argv[])
{
printf ( "By the time you run me "
"I will be destroyed " );
// Array of pointers to command line arguments
remove (argv[0]);
// Note: argv[0] will contain the executable
// file i.e. 'a.out'
return 0;
}


步骤:

  1. 打开航站楼。
  2. 在终端上键入以下命令:
     gcc self.c 
  3. 这将创建 a、 出去 文件
  4. 在终端上键入以下命令:
     ./a.out 

输出:

By the time you run me, I will be destroyed

在上面显示的输出之后 a、 出去 文件将被删除。我们的工作就这样结束了。

© 版权声明
THE END
喜欢就支持一下吧
点赞10 分享