w3resource

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.

Syntax:

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");
   }   
   return(0);
}

Output:

File deleted successfully

C Programming Code Editor:

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



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://www.w3resource.com/c-programming/stdio/c_library_method_remove.php