C program to delete a file

In programming, working with files is very important and every programming language has its own set of functions or library that help in manipulation of files.

In C Programming Language also there is a function remove which can be used by the programmer to delete a file.

remove() function in c programming

The remove function is used to delete the file whose name is specified. This function is in the stdio header file.


remove (“file_name”);


The function accepts one parameter which is the name of the file that is to be deleted.

File name can also be the path to the file but only if the system supports it.

return value

It returns zero, if the deletion operation is successfully completed. otherwise a non zero return on failure.


int main() {
   int del = remove("textFile.txt");
   if (!del)
      printf("The file is Deleted successfully");
      printf("the file is not Deleted");
   return 0;


The file is Deleted successfully

Updated on: 22-Nov-2019

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started