tmpnam() function in C
Last Updated :
06 Sep, 2017
The tmpnam() function is a special function which is declared inside “stdio.h” header file. It generates a different temporary file name each time it is called up to at least TMP_MAX names. Here TMP_MAX represents maximum number of different file names that can be produce by tmpnam() function. If it is called more than TMP_MAX times, the behavior is implementation dependent.Here, L_tmpnam define the size needed for an array of char to hold the result of tmpnam.
Syntax :
char *tmpnam(char *str)
s : The character array to copy the file name.
It generates and returns a valid temporary
filename which does not exist.
If str is null then it simply returns the tmp file name.
#include <stdio.h>
int main( void )
{
char generate[L_tmpnam + 1];
tmpnam (generate);
puts (generate);
return 0;
}
|
Output:
The file names are dependent on running machine, which can be anything.
Example: /tmp/fileRTOA0m
\s260.
\s3ok.
\s5gg. etc
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...