C library functions -remove()
C Standard Library - <stdio.h>
Description
C Library Functionsint remove(const char *filename)Delete the given filenamefilename, so that it is no longer accessible.
Declaration
Below is the declaration of the remove() function.
int remove(const char *filename)
Parameter
- filename-- This is a C string containing the name of the file to be deleted.
Return Value
On success, zero is returned. On error, -1 is returned, and errno is set.
Example
The following example demonstrates the usage of the remove() function.
#include <stdio.h>
#include <string.h>
int main ()
{
int ret;
FILE *fp;
char filename[] = "file.txt";
fp = fopen(filename, "w");
fprintf(fp, "%s", "这里是 example.com");
fclose(fp);
ret = remove(filename);
if(ret == 0)
{
printf("文件删除成功");
}
else
{
printf("错误:不能删除该文件");
}
return(0);
}
Suppose we have a text filefile.txt, the content of which is as follows. We will use the above program to delete the file. Let us compile and run the above program, which will produce the following message, and the file will be permanently deleted.
File deletion successful.other extensions