C 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

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:

void main()
	char name[40];
	int i;
	for(i=0; i<3; i++)
		printf("%s ", name);

C Online Test

« Previous Function Next Function »

Like/Share Us on Facebook 😋