A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://en.cppreference.com/w/cpp/language/../algorithm/../../cpp/../c/io/remove.html below:

remove - cppreference.com

int remove( const char* pathname );

Deletes the file identified by the character string pointed to by pathname.

If the file is currently open by any process, the behavior of this function is implementation-defined. POSIX systems unlink the file name (directory entry), but the filesystem space used by the file is not reclaimed while it is open in any process and while other hard links to the file exist. Windows does not allow the file to be deleted in such cases.

[edit] Parameters pathname - pointer to a null-terminated string containing the path identifying the file to delete [edit] Return value

​0​ upon success or non-zero value on error.

[edit] Notes

POSIX specifies many additional details for the behavior of this function.

[edit] Example
#include <stdio.h>
#include <stdlib.h>
 
int main(void)
{
    FILE* fp = fopen("file1.txt", "w"); // create file
    if (!fp)
    {
        perror("file1.txt");
        return EXIT_FAILURE;
    }
    puts("Created file1.txt");
    fclose(fp);
 
    int rc = remove("file1.txt");
    if (rc)
    {
        perror("remove");
        return EXIT_FAILURE;
    }
    puts("Removed file1.txt");
 
    fp = fopen("file1.txt", "r"); // Failure: file does not exist
    if (!fp)
        perror("Opening removed file failed");
 
    rc = remove("file1.txt"); // Failure: file does not exist
    if (rc)
        perror("Double-remove failed");
 
    return EXIT_SUCCESS;
}

Possible output:

Created file1.txt
Removed file1.txt
Opening removed file failed: No such file or directory
Double-remove failed: No such file or directory
[edit] References
[edit] See also

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4