Friday, September 16, 2011

Deleting a File in C

Here is the program to delete a file in C......
#include <stdio.h>
#include<stdio.h>
#include<errno.h>
int main(void)
{
   char file[80];
   int i;
   clrscr();
   printf("File to delete: ");
   gets(file);
   i=remove(file);
   if(i==0)
   {
   printf("file removed");
   }
   else
   {
   if(errno==ENOENT)
   printf("\nNo such file exists");
   if(errno==EACCES)
   printf("\nPermission denied");
   }
   getch();
   return 0;
}
Feel Free to Comment if any point is not clear.........