C programming stdio.h function - int remove(const char *filename)

https:‮w//‬ww.theitroad.com

In C programming, the remove() function is defined in the stdio.h header file and is used to delete a file. The function takes a single argument, which is a pointer to a null-terminated string containing the name of the file to be deleted:

int remove(const char *filename);

The remove() function returns 0 if the file is successfully deleted, or a non-zero value if an error occurs. An error can occur if the file does not exist or cannot be deleted for some other reason.

Here's an example of how to use the remove() function to delete a file:

#include <stdio.h>

int main() {
    char *filename = "example.txt";
    int result = remove(filename);

    if (result == 0) {
        printf("%s was deleted successfully.\n", filename);
    } else {
        printf("Error deleting %s.\n", filename);
    }

    return 0;
}

In the above example, the remove() function is used to delete the file named "example.txt". If the file is successfully deleted, a message is printed to the console indicating that the file was deleted. If an error occurs, a different message is printed to the console.