Delete file in C

File handling also allows to delete existing file in C. C has remove() function in <stdio.h> header file which takes file name as argument and deletes the file if exists and return 0.

Syntax

remove("filename");

Example


#include<stdio.h>

void main()
{
    int rv = remove("myfile.txt");
    if(rv == 0)
      printf("File successfully deleted.");
    else
       printf("Unable to delete");
}
Output:
File successfully deleted. (If Exists)