The remove
function deletes the file with the filename given as a parameter. This is depicted below:
The function is accessible via the stdio.h
library.
A string containing the name of the file to be deleted is given as a parameter.
int remove(const char* filename)
On successful execution, the function returns 0
. Otherwise, a non-zero number is returned.
#include <stdio.h>#include <string.h>int main() {int ret;char filename[] = "this_file.txt"; // name of the file to be deletedret = remove(filename); // call the remove functionif(ret == 0) //succesful deletion{printf("The file was deleted.");}else // unsuccessful deletion{printf("Unable to delete file.");}}
Free Resources