C程序删除一个文件

这个 去除 C/C++中的函数可用于删除文件。如果文件删除成功,函数返回0,其他函数返回非零值。

null

#include<stdio.h>
int main()
{
if ( remove ( "abc.txt" ) == 0)
printf ( "Deleted successfully" );
else
printf ( "Unable to delete the file" );
return 0;
}


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

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

#include<stdio.h>
#include<stdlib.h>
int main( int c, char *argv[])
{
printf ( "By the time you will compile 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;
}
// This code is contributed by  MAZHAR IMAM KHAN.


输出:

By the time you will compile me I will be destroyed

在上面显示的输出之后 a、 出去 文件将被删除。 如果您发现任何不正确的地方,或者您想分享有关上述主题的更多信息,请写评论

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