C 程式設計/stdio.h/remove
外觀
remove 是 C 程式語言中用於刪除特定檔案的函式。它包含在 C 標準庫標頭檔案 stdio.h 中。
函式原型如下
int remove ( const char * filename );
如果成功,該函式返回零。失敗時返回非零值,並且 errno 變數設定為相應的錯誤程式碼。
以下程式演示了 remove 的常見用法
#include <stdio.h>
int main()
{
const char *filename = "a.txt";
remove (filename);
return 0;
}
實現簡單的刪除工具
#include <stdio.h>
int main(char* argv[], int argc)
{
if (argc > 1) {
return remove (argv[1]);
}else{
return -1;
}
}