c语言删除文件remove_C程序删除文件
原標(biāo)題:C程序刪除文件
C / C ++中的remove函數(shù)可用于刪除文件。 如果成功刪除文件,則該函數(shù)返回0,其他返回非零值。
#include
int main()
{
if (remove("abc.txt") == 0)
printf("Deleted successfully");
else
printf("Unable to delete the file");
return 0;
}
在C中使用remove()函數(shù),我們可以編寫一個(gè)程序,它可以在編譯和執(zhí)行后自行銷毀。
說(shuō)明:這可以使用C中的remove函數(shù)來(lái)完成。請(qǐng)注意,這是在Linux環(huán)境中完成的。因此,remove函數(shù)被輸入命令行參數(shù)中的第一個(gè)參數(shù),即編譯后創(chuàng)建的a.out文件(可執(zhí)行文件)。因此該程序?qū)⒈讳N毀。
#include
#include
int main(int c, char *argv[])
{
printf("By the time you will compile me I will be destroyed \n");
// 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.out文件。返回搜狐,查看更多
責(zé)任編輯:
總結(jié)
以上是生活随笔為你收集整理的c语言删除文件remove_C程序删除文件的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 九阴真经手游宝物获取方法介绍
- 下一篇: 自动发现_清华发布首个自动图学习框架,或