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.........

2 comments:

  1. i=remove(file);
    wat is this line indicates?
    is remove is an inbulid function?

    ReplyDelete
  2. Yes It is a inbuilt function.The prototype for this is:
    int remove(const char *filename);

    ReplyDelete

Feel free to comment......