C庫函數 int remove(const char *filename)刪除的給定檔案名,以便它不再訪問。
聲明
以下是remove()函數的聲明。
int remove(const char *filename)
參數
-
filename -- 這是C包含要刪除的檔的名稱的字串。
返回值
成功則返回0。錯誤則返回-1,設置errno。
例子
下麵的例子演示了如何使用remove()函數。
#include <stdio.h> #include <string.h> int main () { int ret; char filename[] = "file.txt"; ret = remove(filename); if(ret == 0) { printf("File deleted successfully"); } else { printf("Error: unable to delete the file"); } return(0); }
假設我們有一個文本檔file.txt 的一些內容。所以我們要刪除此檔,用上面的程式。讓我們編譯和運行上面的程式,這將產生以下消息將被永久刪除檔。
File deleted successfully
上一篇:
fwrite() - C語言庫函數
下一篇:
rename() - C語言庫函數