使用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; } |
步骤:
- 打开航站楼。
- 在终端上键入以下命令:
gcc self.c
- 这将创建 a、 出去 文件
- 在终端上键入以下命令:
./a.out
输出:
By the time you run me, I will be destroyed
在上面显示的输出之后 a、 出去 文件将被删除。我们的工作就这样结束了。
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END