w3resource logo


C Programming Exercises

C Exercises: Remove a file from the disk

Secondary Nav

C File Handling : Exercise-15 with Solution

Write a program in C to remove a file from the disk.
Test Data :
Input the name of file to delete : test.txt
Expected Output :

 The file test.txt is deleted successfully..!! 

C Code:

#include <stdio.h>

void main()
{
	int status;
	char fname[20];
	printf("\n\n Remove a file from the disk :\n");
	printf("----------------------------------\n"); 	
	printf(" Input the name of file to delete : ");
	scanf("%s",fname);
	status=remove(fname);
	if(status==0)
	{
		printf(" The file %s is deleted successfully..!!\n\n",fname);
	}
	else
	{
		printf(" Unable to delete file %s\n\n",fname);
	}
}

Flowchart :

Flowchart: Remove a file from the disk

C Practice online:


#include <stdio.h>

void main()
{
	int status;
	char fname[20];
	printf("\n\n Remove a file from the disk :\n");
	printf("----------------------------------\n"); 	
	printf(" Input the name of file to delete : ");
	scanf("%s",fname);
	status=remove(fname);
	if(status==0)
	{
		printf(" The file %s is deleted successfully..!!\n\n",fname);
	}
	else
	{
		printf(" Unable to delete file %s\n\n",fname);
	}
}

Improve this sample solution and post your code through Disqus.



Join our Question Answer community to learn and share your programming knowledge.

Help the community:

PHP: Loop

JavaScript: Delete duplicates in an array

Oracle: Round the number