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()



Share this Tutorial / Exercise on : Facebook and Twitter

C Programming: Tips of the Day

What's an object file in C?

An object file is the real output from the compilation phase. It's mostly machine code, but has info that allows a linker to see what symbols are in it as well as symbols it requires in order to work. (For reference, "symbols" are basically names of global objects, functions, etc.)

A linker takes all these object files and combines them to form one executable (assuming that it can, i.e.: that there aren't any duplicate or undefined symbols). A lot of compilers will do this for you (read: they run the linker on their own) if you don't tell them to "just compile" using command-line options. (-c is a common "just compile; don't link" option.)

Ref : https://bit.ly/3CbzF8M