Home C-tutorials C file delete example



C file delete example
Posted on: February 5, 2009 at 12:00 AM
This section illustrates you to delete a file in C. You can see in the given example that we want to remove the file HELLO.txt.

C file delete example

     

This section illustrates you to delete a file in C. You can see in the given example that we want to remove the file HELLO.txt. For this, we have used the library function remove() which deletes the file HELLO.txt. In case if the file will not be deleted, the function perror() prints the error message on the console.

Here i am using TurboC++ IDE and my source file is in the C:\TC\BIN directory and the file to be deleted Hello.txt  should be first placed inside the same bin directory.

Here is the code:

FILEDELE.C

#include <stdio.h>
#include <conio.h>
void main() {
  if (remove("HELLO.txt"== -1)
  perror("Error in deleting a file");
  getch();
}

When you run the above example, the file HELLO.txt gets removed.

Download Source Code:

Related Tags for C file delete example:
cfileantdeleteioremovethismovetxtexampletoexameilsectioncaninmnttrwancaletesemrateratesxaxampsdeleeatishellohallivmplstrxtwantssthsthellohatpleplmovono


More Tutorials from this section

Ask Questions?    Discuss: C file delete example  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.