Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simple Delete File Program in ANSI C for Windows

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?

like image 368
BuddyJoe Avatar asked Jan 16 '23 20:01

BuddyJoe


1 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.

like image 136
Rivasa Avatar answered Jan 29 '23 07:01

Rivasa