tmpnam()函数是一个特殊函数,它在“stdio.h”头文件中声明。每次至少调用TMP_MAX名称时,它都会生成一个不同的临时文件名。在此,TMP_MAX表示tmpnam()函数可以产生的最大不同文件名数。如果它的调用次数超过了TMP_MAX次,则该行为取决于实现。此处,L_tmpnam定义了一个char数组保存tmpnam结果所需的大小。
用法:
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.
// C program to generate random temporary file names. 
#include <stdio.h> 
int main(void) 
{ 
    // L_tmpnam declared in the stdio.h file. 
    // L_tmpnam define length of the generated file name. 
    char generate[L_tmpnam + 1]; // Add +1 for the null character. 
    tmpnam(generate); 
    puts(generate); 
    return 0; 
}输出:
The file names are dependent on running machine, which can be anything.
Example:/tmp/fileRTOA0m
         \s260.
         \s3ok.
         \s5gg. etc
相关用法
- C语言 strlwr()用法及代码示例
- C语言 tolower()用法及代码示例
- C语言 toupper()用法及代码示例
- C语言 putchar()用法及代码示例
- C++ ldexp()用法及代码示例
- C++ wcstoll()用法及代码示例
- C++ iswpunct()用法及代码示例
- C++ iswblank()用法及代码示例
- C++ iswalnum()用法及代码示例
- C++ exp2()用法及代码示例
- C++ feupdateenv()用法及代码示例
- C++ raise()用法及代码示例
- C++ towupper()用法及代码示例
注:本文由纯净天空筛选整理自 tmpnam() function in C。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
