Deleting File in C programming by using remove() function to delete any file from the computer. remove() function takes one string parameter, the parameter will be the path of the file.
#include<stdio.h>
#include<conio.h>
void main()
{
int status;
printf("Deleting file...\n");
status = remove("C://test/MyTxtFile.txt"); //deleting file.
if( status == 0 ) //if delete then
printf("File deleted successfully.\n");
else //if not then
{
printf("Unable to delete the file.\n");
perror("Error"); //'perror' used for printing About error.
}
getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
int status;
char file_name[25];
printf("Enter the name of file you wish to delete: ");
gets(file_name); //user enter file name storing in 'file_name'.
printf("Deleting file...\n");
status = remove(file_name); //deleting.
if( status == 0 ) //if delete then
printf("%s file deleted successfully.\n", file_name);
else //if not then
{
printf("Unable to delete the file\n");
perror("Error"); //'perror' used for printing About error.
}
getch();
}