C programming remove stdio.h


In C programming the <stdio.h> remove function delete the file.Use this function if you want to delete the file permanently.The declaration of the function is given below.

int remove(const char *filename);

Parameters:
filename -The name of the file to be removed.

Return type
int -Return 0 if the operation is successful ,if it fails returns non-zero value.

Some points to note:

i)IF the file is open and ‘remove’ function is called the behavior is undefined.

Code example

int result=remove( “text.txt” );

if( result==0 )
{
printf(“File deleted”);
}

Output,

File deleted

Another code example is given below.

Code example

FILE *fp=fopen( “text.txt” , “r” ); //file open

int result=remove( “text.txt” ); //undefined behavior cause the file is open

if( result==0 )
{
printf(“File deleted”);
}


Related links

->C fopen stdio.h

->C fclose stdio.h

->C rename stdio.h

->C tmpfile stdio.h