This shows you the differences between two versions of the page.
c:stdio.h:tmpnam [2013/01/22 22:02] |
c:stdio.h:tmpnam [2024/02/16 01:05] (current) |
||
---|---|---|---|
Line 1: | Line 1: | ||
+ | {{keywords>wiki library source code example reference}} | ||
+ | |||
+ | ===== tmpnam ===== | ||
+ | <code c> | ||
+ | char *tmpnam(char *str); | ||
+ | </code> | ||
+ | |||
+ | Assigns to s (if s non-null) and returns unique name for a temporary file. Unique name is returned for each of the first TMP_MAX invocations. | ||
+ | |||
+ | ===== C Sourcecode Example ===== | ||
+ | <code c> | ||
+ | /* | ||
+ | * tmpnam example code | ||
+ | * http://code-reference.com/c/stdio.h/tmpnam | ||
+ | */ | ||
+ | |||
+ | #include <stdio.h> /* including standard library */ | ||
+ | //#include <windows.h> /* uncomment this for Windows */ | ||
+ | |||
+ | |||
+ | int main ( void ) | ||
+ | { | ||
+ | FILE *tmpstream; | ||
+ | char *tmpfile; | ||
+ | |||
+ | tmpfile = tmpnam(NULL); | ||
+ | tmpstream= fopen(tmpfile, "w"); | ||
+ | |||
+ | if ( tmpstream == NULL) { | ||
+ | perror("Error opening tmp stream"); | ||
+ | } | ||
+ | |||
+ | fputs("Test for tmpnam", tmpstream); | ||
+ | |||
+ | rename(tmpfile, "test.txt"); | ||
+ | fclose(tmpstream); | ||
+ | return 0; | ||
+ | |||
+ | } | ||
+ | |||
+ | </code> | ||
+ | |||
+ | content of test.txt after executing ./tmpnam | ||
+ | <code c> | ||
+ | Test for tmpnam | ||
+ | </code> | ||
+ | |||
+ | ==== output ==== | ||
+ | ./tmpnam | ||
+ | |||
+ | |||