Pages

To Delete a File in C

Friday 28 June 2013
The C program to delete a file that is entered by the user, the file will be deleted, be present in the directory where the executable file of the program is available. The file extension must contain, remove the macro used to delete the file. If there is an error to delete the file, an error message will be displayed with perror function.

#include<stdio.h>

main()
{
   int status;
   char file_name[25];

   printf("Enter the name of file you wish to delete\n");
   gets(file_name);

   status = remove(file_name);

   if( status == 0 )
      printf("%s file deleted successfully.\n",file_name);
   else
   {
      printf("Unable to delete the file\n");
      perror("Error");
   }
  return 0;
}

No comments:

Post a Comment