sprintf

Writes output to a specified character array under format control

Local Servers:blocking
Remote Servers:N/A
Classification:ANSI
Service:String Manipulation

Syntax

  #include <stdio.h>  
   
  int sprintf  (  
     char         *buf,   
     const char   *format,   
     ... );
  

Parameters

buf
(OUT) Points to the character array into which to place the output.
format
(IN) Points to the format control string.

Return Values

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.

Remarks

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.

See Also

fprintf, printf (Single and Intra-File Services), vsprintf

Example

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());  
  }