vsprintf

Formats data under control of the format control string

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

Syntax

  #include <stdarg.h>  
  #include <stdio.h>  
   
  int  vsprintf  (  
     char         *buf,   
     const char   *format,   
     va_list       arg);
  

Parameters

buf
(OUT) Points to the buffer to which to write the result.
format
(IN) Points to the format control string.
arg
(IN) Specifies a variable argument.

Return Values

The vsprintf function returns the number of characters written, or a negative value if an output error occurred.

Remarks

The vsprintf function formats data under control of the format control string and writes the result to buf. The format string is described under the description for printf. The vsprintf function is equivalent to sprintf, with the variable argument list replaced with arg, which has been initialized by the va_start macro.

See Also

fprintf, printf (Single and Intra-File Services), sprintf, va_arg, va_end, va_start

Example

This example shows the use of vsprintf in a general error message routine.

  #include <stdarg.h>  
  #include <stdio.h>  
  #include <striup.h>  
   
  char msgbuf[80];  
  char *fmtmsg (char *format, ... )  
   
  {  
     va_list arglist;  
     va_start (arglist, format);  
     strcpy (msgbuf, "Error: ");  
     vsprintf (&msgbuf[7], format, arglist);  
     va_end (arglist);  
     return (msgbuf);  
  }