tmpnam()函数是一个特殊函数,在“stdio.h”头文件中声明。每次调用至少TMP_MAX name时,它都会生成不同的临时文件名。这里,TMP_MAX表示tmpnam()函数可以生成的不同文件名的最大数量。如果调用次数超过TMP_MAX,则该行为取决于实现。这里,L_tmpnam定义了字符数组保存tmpnam结果所需的大小。
null
语法:
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
本文由 比沙尔·库马尔·杜比 .如果你喜欢GeekSforgek,并想贡献自己的力量,你也可以使用 贡献极客。组织 或者把你的文章寄到contribute@geeksforgeeks.org.看到你的文章出现在Geeksforgeks主页上,并帮助其他极客。
如果您发现任何不正确的地方,或者您想分享有关上述主题的更多信息,请写下评论。
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END