codescracker


c

C Program to Delete Files



« Previous Program Next Program »


Delete Files in C

To delete files in C programming, you have to ask to the user to enter the file name now delete the file using the function remove(). If the file would be deleted then it will return 0, otherwise it will not return 0

C Programming Code to Delete Files

Following C program ask to the user to enter a file name which he or she want to delete, then the following program delete the file :

/* C Program - Delete Files */
		
#include<stdio.h>
#include<conio.h>
void main()
{
	clrscr();
	int status;
	char fname[20];
	printf("Enter name of file, you want to delete : ");
	gets(fname);
	status=remove(fname);
	if(status==0)
	{
		printf("file %s deleted successfully..!!\n",fname);
	}
	else
	{
		printf("Unable to delete file %s\n",fname);
		perror("Error Message ");
	}
	getch();
}

When the above c program is compile and executed, it will produce the following result:

c program to delete files

Same Program in Other Programming Language

You may also like same program in other programming languages:


« Previous Program Next Program »



Tools
Calculator

Quick Links
Signup - Login - Give Online Test