From 754bbf7a25a8dda49b5d08ef0d0443bbf5af0e36 Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Sun, 7 Apr 2024 13:41:34 -0500 Subject: new repository --- devdocs/c/io%2Fremove.html | 61 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 devdocs/c/io%2Fremove.html (limited to 'devdocs/c/io%2Fremove.html') diff --git a/devdocs/c/io%2Fremove.html b/devdocs/c/io%2Fremove.html new file mode 100644 index 00000000..5813a48f --- /dev/null +++ b/devdocs/c/io%2Fremove.html @@ -0,0 +1,61 @@ +

remove

Defined in header <stdio.h>
int remove( const char* fname );
+

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

+

If the file is currently open by this or another process, the behavior of this function is implementation-defined (in particular, POSIX systems unlink the file name although the file system space is not reclaimed until the last running process closes the file; Windows does not allow the file to be deleted).

+

Parameters

+ +
fname - pointer to a null-terminated string containing the path identifying the file to delete

Return value

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

+

Notes

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

+

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

References

See also

+ +
renames a file
(function)
C++ documentation for remove
+

+ © cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
+ https://en.cppreference.com/w/c/io/remove +

+
-- cgit v1.2.3