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.

Remove () function in C Picture 1

According to Tutorialspoint

Previous lesson: Function fwrite () in C

Next lesson: rename () function in C

4 ★ | 1 Vote

May be interested

  • How to use the UNIQUE function in Google SheetsHow to use the UNIQUE function in Google Sheets
    the 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 ServerSUM function in SQL Server
    the sql server sum function returns the total value of a column, a data set, or an expression.
  • The ord () function in PythonThe ord () function in Python
    the built-in ord () function in python returns an integer representing the unicode code of the specified character.
  • RIGHT function in SQL ServerRIGHT function in SQL Server
    the 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 PythonInt () function in Python
    the int () function in python returns an integer object from any number or string.
  • AVG function in SQL ServerAVG function in SQL Server
    the 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 PythonHex () function in Python
    the hex () function is one of python's built-in functions, used to convert an integer into the corresponding hexadecimal form.
  • ABS function in SQL ServerABS function in SQL Server
    this 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 function id () in Python
    the built-in function id () in python returns a single integer value that identifies an object.
  • DATEPART function in SQL ServerDATEPART function in SQL Server
    the 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)