📜  C中的tmpnam()函数

📅  最后修改于: 2021-05-25 18:36:40             🧑  作者: Mango

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 
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的C基础课程》。