This shows you the differences between two versions of the page.
c:stdio.h:remove [2013/01/22 22:02] |
c:stdio.h:remove [2024/02/16 01:05] (current) |
||
---|---|---|---|
Line 1: | Line 1: | ||
+ | {{keywords>wiki library source code example reference}} | ||
+ | |||
+ | ====== remove ====== | ||
+ | <code c> | ||
+ | int remove(const char *filename); | ||
+ | </code> | ||
+ | Removes specified file. Returns non-zero on failure. | ||
+ | |||
+ | ===== Example Source ===== | ||
+ | <code c> | ||
+ | /* | ||
+ | * remove example code | ||
+ | * http://code-reference.com/c/stdio.h/remove | ||
+ | */ | ||
+ | |||
+ | #include <stdio.h> /* including standard library */ | ||
+ | //#include <windows.h> /* uncomment this for Windows */ | ||
+ | |||
+ | #define FILENAME "test_tmp.txt" | ||
+ | |||
+ | int main ( void ) | ||
+ | { | ||
+ | FILE *tmpfile; | ||
+ | char string[20]; | ||
+ | tmpfile = fopen(FILENAME, "w"); | ||
+ | |||
+ | if (tmpfile == 0 ) { | ||
+ | perror("cannot open file"); | ||
+ | } | ||
+ | |||
+ | fprintf (tmpfile, "temporary file for c remove example\n"); | ||
+ | fclose(tmpfile); | ||
+ | |||
+ | remove (FILENAME); /* you can also use remove("test_tmp.txt"); */ | ||
+ | |||
+ | return 0; | ||
+ | } | ||
+ | </code> | ||
+ | |||
+ | ==== output ==== | ||
+ | ./remove | ||
+ | |||
+ | file will be created | ||
+ | write text into file "temporary file for c remove example" | ||
+ | close the file | ||
+ | |||
+ | file will be deletet | ||