The remove function in C/C++ can be used to delete a file. The function returns 0 if files is deleted successfully, other returns a non-zero value.
Using remove() function in C, we can write a program which can destroy itself after it is compiled and executed.
Explanation: This can be done using the remove function in C. Note that, this is done in Linux environment. So, the remove function is fed the first parameter in command line argument i.e. a.out file (executable file) created after compiling . Hence the program will be destroyed.
By the time you will compile me I will be destroyed
After the output shown above, the a.out file will be removed.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above
- Program to delete a line given the line number from a file
- C program to copy contents of one file to another file
- C++ program to create a file
- LEX program to add line numbers to a given file
- C Program to print contents of file
- C Program to find size of a File
- C++ program to append content of one text file to another
- C++ program to print unique words in a file
- C Program to count the Number of Characters in a File
- C Program to count number of lines in a file
- C Program to merge contents of two files into a third file
- C Program for Lower Case to Uppercase and vice-versa in a file
- Write a C program that displays contents of a given file like 'more' utility in Linux
- Lex program to take input from file and remove multiple spaces, lines and tabs
- C++ program to read file word by word