Standard Library Functions in C

adplus-dvertising
remove() Function
Previous Home Next

Description

The c library function, The remove( ) function erases the file specified by filename. This is an operation performed directly on a file identified by its filename; No streams are involved in the operation. Proper file access shall be available.

Declaration

Following is the declaration for remove() function.

int remove(const char *filename)

Parameters

filename - C string containing the name of the file to be deleted.

Return Value

It returns zero if the file was successfully deleted and nonzero if an error occurred.

Example

#include<stdio.h>
 
main()
{
   int status;
   char name[25];
 
   printf("Enter the name of file you delete\n");
   gets(file_name);
 
   status = remove(name);
 
   if( status == 0 )
      printf("%s file deleted successfully.\n",name);
   else
   {
      printf("Unable to delete the file\n");
      perror("Error");
   }
 
   return 0;
}

Output

txt.c file deleted successfully.
Previous Home Next