跳轉到內容

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;
    }
}
[編輯 | 編輯原始碼]
華夏公益教科書