remove() – C语言库函数
C库函数 int remove(const char *filename)删除的给定文件名,以便它不再访问。
声明
以下是remove()函数的声明。
int remove(constchar*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