
- The C Standard Library
- C Library - Home
- C Library - <assert.h>
- C Library - <ctype.h>
- C Library - <errno.h>
- C Library - <float.h>
- C Library - <limits.h>
- C Library - <locale.h>
- C Library - <math.h>
- C Library - <setjmp.h>
- C Library - <signal.h>
- C Library - <stdarg.h>
- C Library - <stddef.h>
- C Library - <stdio.h>
- C Library - <stdlib.h>
- C Library - <string.h>
- C Library - <time.h>
- C Standard Library Resources
- C Library - Quick Guide
- C Library - Useful Resources
- C Library - Discussion
- C Programming Resources
- C Programming - Tutorial
- C - Useful Resources
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C library function - tmpnam()
Description
The C library function char *tmpnam(char *str) generates and returns a valid temporary filename which does not exist. If str is null then it simply returns the tmp file name.
Declaration
Following is the declaration for tmpnam() function.
char *tmpnam(char *str)
Parameters
str − This is the pointer to an array of chars where the proposed tempname will be stored as a C string.
Return Value
Return value is a pointer to the C string containing the proposed name for a temporary file. If str was a null pointer, this points to an internal buffer that will be overwritten the next time this function is called.
If str was not a null pointer, str is returned. If the function fails to create a suitable filename, it returns a null pointer.
Example
The following example shows the usage of tmpnam() function.
#include <stdio.h> int main () { char buffer[L_tmpnam]; char *ptr; tmpnam(buffer); printf("Temporary name 1: %s\n", buffer); ptr = tmpnam(NULL); printf("Temporary name 2: %s\n", ptr); return(0); }
Let us compile and run the above program to produce the following result −
Temporary name 1: /tmp/filebaalTb Temporary name 2: /tmp/filedCIbb0