codescracker


c

C tmpnam()



« Previous Function Next Function »


tmpnam()

The tmpnam() function generates a unique filename and stores it in the array pointed to by name. This array must be at leas L_tmpnam character long. The L_tmpnam is defined in <stdio.h>. The main purpose of tmpnam is to generate a temporary filename that is different from any other file in the current disk directory.

The function can be called up to TMP_MAX times. The TMP_MAX is defined in <stdio.h> and it will be at least 25. Each time tmpnam() is called, it will generate a new temporary filename.

tmpnam() Syntax

#include<stdio.h>
char *tmpnam(char *name);

A pointer to name is returned on success, otherwise returns a null pointer.

tmpnam() Example

Following c program displays the three unique temporary filenames:

#include<stdio.h>
#include<conio.h>
void main()
{
	clrscr();
	char name[40];
	int i;
	for(i=0; i<3; i++)
	{
		tmpnam(name);
		printf("%s ", name);
	}
	getch();
}

« Previous Function Next Function »



Tools
Calculator

Quick Links
Signup - Login - Give Online Test