sprintf
Writes output to a specified character array under format control
#include <stdio.h>
int sprintf (
char *buf,
const char *format,
... );
The sprintf function returns the number of characters written into the array, not counting the terminating NULL character. An error can occur while converting a value for output.
The sprintf function is equivalent to fprintf, except that the argument buf specifies a character array into which the generated output is placed, rather than to a file. A NULL character is placed at the end of the generated character string. The format string is described under the description for the printf function.
To create a temporary file name using a counter:
#include <stdio.h>
char *make_temp_name ()
{
static int tempCount=0;
static char namebuf[13];
sprintf (namebuf, "ZZ%o6d.TMP", tempCount++);
return (namebuf);
}
main ()
{
int i;
for (i=0; i<3; i++)
printf ("%s\n", make_temp_name());
}