Remove () function in C
The int remove (const char * filename) function in Library C standard deletes the filename so it is no longer accessible.
The int remove (const char * filename) function in Library C standard deletes the filename so it is no longer accessible.
Declare the remove () function in C
Below is the declaration for the remove () function in C:
int remove ( const char * filename )
Parameters
filename - This is the string containing the file name to be deleted.
Returns the value
If successful, return 0. If there is an error, return -1 and errno are set appropriately.
For example
The following C program illustrates the use of the remove () function in C:
#include #include int main () { int ret ; FILE * fp ; char filename [] = "baitapc.txt" ; fp = fopen ( filename , "w" ); fprintf ( fp , "%s" , "Hoc C co ban va nang cao tai QTM !!!" ); fclose ( fp ); ret = remove ( filename ); if ( ret == 0 ) { printf ( "Xoa file thanh cong !!!" ); } else { printf ( "Error: khong the xoa file tren" ); } return ( 0 ); }
Suppose we have baitapc.txt with some content. We are about to delete this file by using the above program. Compiling and running the above program will give the following message and the file has been permanently deleted.
According to Tutorialspoint
Previous lesson: Function fwrite () in C
Next lesson: rename () function in C
You should read it
Maybe you are interested
The whole scene of meteorites hitting the Earth during the past 33 years, why can't we feel it? The most beautiful meteor shower of the year and amazing astronomical phenomena in August Is Proxima b our 'neighbor' planet? Why have scientists found Proxima b - '2nd Earth' until now? The mystery of the numbers of Proxima b: The 'Second Earth' on the planet may exist life Early in the morning, Venus and Jupiter will meet in the sky, don't miss this magical, rare moment!