Remove () function in C
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
May be interested
- How to use the UNIQUE function in Google Sheetsthe unique function in google sheets is a handy function that helps you find unique values in a data set and remove any duplicates.
- SUM function in SQL Serverthe sql server sum function returns the total value of a column, a data set, or an expression.
- The ord () function in Pythonthe built-in ord () function in python returns an integer representing the unicode code of the specified character.
- RIGHT function in SQL Serverthe article will explore and guide you how to use the right function in sql server to extract some characters from the right side of a given string.
- Int () function in Pythonthe int () function in python returns an integer object from any number or string.
- AVG function in SQL Serverthe avg function in sql server returns the average value of an expression or average value according to the specified column of the selected row.
- Hex () function in Pythonthe hex () function is one of python's built-in functions, used to convert an integer into the corresponding hexadecimal form.
- ABS function in SQL Serverthis article will show you in detail how to use the abs () handling function in sql server with specific syntax and examples to better visualize and capture functions.
- The function id () in Pythonthe built-in function id () in python returns a single integer value that identifies an object.
- DATEPART function in SQL Serverthe datepart function in sql server returns a time value of the input argument, which can be day, month, year, quarter, hour, minute, second, millisecond ... the return value is an integer type (int)