C remove() function

C library function - remove()

The remove() function is used to delete a given file, named by the pathname pointed to by path.


int remove(const char *filename)

remove() function Parameters:

Name Description Required /Optional
filename The name of filename to be removed... Required

Return value from remove() function:

  • The remove() function returns 0 if it successfully deletes the file.
  • A nonzero return value indicates an error.

Example: remove() function

The following example shows how to remove access to a file named /home/test.txt:

#include <stdio.h>
#include <string.h>

int main () {
   int status;
   char filename[] = "e:/test.txt";
   status = remove(filename);

   if(status == 0) {
      printf("File deleted successfully");
   } else {
      printf("Error: unable to remove the file");


File deleted successfully

C Programming Code Editor:

Previous C Programming: C remove()
Next C Programming: C rename()

Follow us on Facebook and Twitter for latest update.