C tmpnam() function
C library function - tmpnam()
The tmpnam() function is used to generate a string that is a valid pathname that does not name an existing file.
Syntax:
char *tmpnam(char *s);
tmpnam() Parameters:
Name | Description | Required /Optional |
---|---|---|
s | Stores the file name in s. | Required |
Return value from tmpnam()
- Upon successful completion, tmpnam() shall return a pointer to a string.
- If no suitable string can be generated, the tmpnam() function shall return a null pointer.
Example: tmpnam() function.
Following example calls tmpnam() function to create a valid file name.
#include <stdio.h>
int main(void)
{
char *file_name;
if ((file_name = tmpnam(NULL)) !=NULL)
printf("%s can be used as a file name.\n", file_name);
else
printf("Cannot create a unique file name\n");
}
Output:
\sge4. can be used as a file name.
C Programming Code Editor:
Previous C Programming: C tmpfile()
Next C Programming: C fprintf()
- Weekly Trends
- Python Interview Questions and Answers: Comprehensive Guide
- Scala Exercises, Practice, Solution
- Kotlin Exercises practice with solution
- MongoDB Exercises, Practice, Solution
- SQL Exercises, Practice, Solution - JOINS
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- JavaScript String Exercises
- JavaScript HTML Form Validation
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join