Looking for a simple program to a delete a file written in ANSI C.
Just as an example how would you delete a file at "C:\test.txt" with C?
- linux.die.net/man/3/unlinkxdazz– xdazz2012-08-14 08:17:34 +00:00Commented Aug 14, 2012 at 8:17
- possible duplicate of unlink vs remove in c++AndersK– AndersK2012-08-14 08:17:44 +00:00Commented Aug 14, 2012 at 8:17
Add a comment |
3 Answers
You can delete a file from the OS using the remove() function. Like so:
#include <stdio.h> int main(){ if(remove("HELLO.txt") == -1) perror("Error in deleting a file"); return 0; } The remove() function is defined in stdio.h. Here are some docs.