C Library Function - remove()
Description
C library function *int remove(const char filename) Deletes the given filename filename, so that it can no longer be accessed.
Declaration
The following is the declaration of the remove() function.
int remove(const char *filename)
Parameters
- filename -- This is a C string containing the name of the file to be deleted.
Return Value
On success, it returns zero. On error, it returns -1 and sets errno.
Example
The following example demonstrates the use of the remove() function.
#include
#include
int main ()
{
int ret;
FILE *fp;
char filename[] = "file.txt";
fp = fopen(filename, "w");
fprintf(fp, "%s", "这里是 runoob.com");
fclose(fp);
ret = remove(filename);
if(ret == 0)
{
printf("文件删除成功");
}
else
{
printf("错误:不能删除该文件");
}
return(0);
}
Suppose we have a text file file.txt, whose contents are as follows. We will use the above program to delete this file. Let's compile and run the above program, which will produce the following message and the file will be permanently deleted.
文件删除成功
C Standard Library -