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.

Picture 1 of Remove () function in C

According to Tutorialspoint

Previous lesson: Function fwrite () in C

Next lesson: rename () function in C

Update 25 May 2019
Category

System

Mac OS X

Hardware

Game

Tech info

Technology

Science

Life

Application

Electric

Program

Mobile