Deleting a file using remove() C function in C program
Compiler: Visual C++ Express Edition 2005
Compiled on Platform: Windows Xp Pro with SP2
Header file: Standard
Additional library: none/default
Additional project setting: Set project to be compiled as C
Project -> your_project_name Properties -> Configuration Properties -> C/C++ -> Advanced -> Compiled As: Compiled as C Code (/TC)
Other info: The deleted file cannot be recovered
To do: Deleting a file using the remove() C function
To show: How to use the remove() C function to delete a given file
// Demonstrate the remove() function
// declare an array to store file name...
printf("Enter the filename to be deleted: ");
// check any error...
if(remove(filename) == 0)
printf("File %s has been deleted.\n", filename);
fprintf(stderr, "Error deleting file %s.\n", filename);
Enter the filename to be deleted: C:\testfour.txt
File C:\testfour.txt has been deleted.
Press any key to continue . . .