codescracker


c

C remove()



« Previous Function Next Function »


remove()

The remove() function erases the file or delete the file specified by fname.

remove() Syntax

#include<stdio.h>
int remove(const char *fname);

The remove() function returns zero if the file was successfully deleted, otherwise returns non-zero on error occurred.

remove() Example

Following c program remove or delete the file whose name is entered by the user:

#include<stdio.h>
#include<conio.h>
void main()
{
	clrscr();
	char fname[20];
	printf("Enter the filename with extension (like demo.txt) to delete the file : ");
	gets(fname);
	if(remove(fname))
	{
		printf("Error occurred in removing or deleting the file..!!\n");
		printf("Press any key to exit..\n");
		getch();
		exit(1);
	}
	printf("File removed successfully..!!");
	getch();
}

« Previous Function Next Function »



Tools
Calculator

Quick Links
Signup - Login - Give Online Test