[ First ] [ Previous ] [ Next ] [ Last ] [ Manuals ]
tmpnam

Create a unique temporary filename.
Compatibility:
This function is compatible with the following targets:
Prototype:
#include <stdio.h>
char *tmpnam(char *s);
Parameters:
Parameters for this facility are:
Remarks:
The tmpnam() functions creates a valid filename character string that will not conflict with any existing filename. A program can call the function up to TMP_MAX times before exhausting the unique filenames tmpnam() generates. The TMP_MAX macro is defined in stdio.h.
The s argument can either be a null pointer or pointer to a character array. The character array must be at least L_tmpnam characters long. The new temporary filename is placed in this array. The L_tmpnam macro is defined in stdio.h.
If s is NULL, tmpnam() returns with a pointer to an internal static object that can be modified by the calling program.
Unlike tmpfile(), a file created using a filename generated by the tmpnam() function is not automatically removed when it is closed.
Return:
tmpnam() returns a pointer to a character array containing a unique, non-conflicting filename. If s is a null pointer (NULL), the pointer refers to an internal static object. If s points to a character array, tmpnam() returns the same pointer.
See Also:
"fopen"
"tmpfile"
Example of tmpnam() usage.:
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
FILE *f;
char *tempname;
int c;
// get a unique filename
tempname = tmpnam("tempwerks");
// create a new file for output
if ( (f = fopen(tempname, "w")) == NULL) {
printf("Can't open temporary file %s.\n", tempname);
exit(1);
}
// output text to the file
fprintf(f, "shoe shirt tie trousers\n");
fprintf(f, "province\n");
// close the file
fclose(f);
// delete the file
remove(tempname);
return 0;
}
[ First ] [ Previous ] [ Next ] [ Last ] [ Manuals ]
Visit the Metrowerks website at: http://www.metrowerks.com
For assistance contact Metrowerks Technical Support at: cw_support@metrowerks.com
Copyright © 2000, Metrowerks Corp. All rights reserved.
Last updated: August 16, 2000