Saturday, June 18, 2016

C program to delete a given file.

NOTE: Be careful while executing following program. This program will delete file which you enter at run time.

C program to delete a given file.


#include<stdio.h>
int main()
{
   int file_check_flag;
   char file_name[30];
   printf("Enter file name to be deleted:\n");

   gets(file_name);

   file_check_flag = remove(file_name);

   if( file_check_flag == 0 )
      printf("Your file %s is deleted successfully.\n",file_name);
   else
      printf("Unable to delete %s file.\n",file_name);
   return 0;
}

Output of program

Enter file name to be deleted:

mydata.txt

Your file mydata.txt is deleted successfully.


No comments:

Post a Comment