Format
#include <stdio.h> int remove(const char *filename);
Language Level: ANSI, POSIX, XPG4
remove deletes the file specified by filename.
Note: You cannot remove a nonexistent file or a file that is open.
Return Value
remove returns 0 if it successfully deletes the file. A
nonzero return value indicates an error.
Example
This example uses remove to remove a file. It issues a
message if an error occurs.
#include <stdio.h>
#define FILENAME "file2rm.mjq"
int main(void)
{
char *FileName =FILENAME;
FILE *fp;
fp = fopen(FileName, "w");
fprintf(fp, "Hello world\n");
fclose(fp);
if (remove(FileName) !=0)
perror("Could not remove file");
else
printf("File\"%s\" removed successfully.\n", FileName);
return 0;
/********************************************************
The output should be:
File "FILENAME" removed successfully. ********************************************************/ }
![]()
rename -- Rename File
![]()
_rmtmp -- Remove Temporary Files
![]()
unlink -- Delete File
<stdio.h>