Warning: main(/www/www/htdocs/style/globals.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/neutrino/lib_ref/v/vsprintf.html on line 1

Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/globals.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/neutrino/lib_ref/v/vsprintf.html on line 1

Warning: main(/www/www/htdocs/style/header.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/neutrino/lib_ref/v/vsprintf.html on line 8

Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/header.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/neutrino/lib_ref/v/vsprintf.html on line 8

vsprintf()

Write formatted output to a buffer (varargs)

Synopsis:

#include <stdio.h>
#include <stdarg.h>

int vsprintf( char* buf,
              const char* format,
              va_list arg );

Arguments:

buf
A pointer to the buffer where you want to function to store the formatted string.
format
A string that specifies the format of the output. The formatting string determines what additional arguments you need to provide. For more information, see printf().
arg
A variable-argument list of the additional arguments, which you must have initialized with the va_start() macro.

Library:

libc

Use the -l c option to qcc to link against this library. This library is usually included automatically.

Description:

The vsprintf() function formats data under control of the format control string, and writes the result to buf.

The vsprintf() function is a “varargs” version of sprintf().

Returns:

The number of characters written, or a negative value if an output error occurred (errno is set).

Examples:

Use vsprintf() in a general error message routine:

#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.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 );
  }

int main( void )
  {
    char *msg;

    msg = fmtmsg( "%s %d %s", "Failed", 100, "times" );
    printf( "%s\n", msg );
    return EXIT_SUCCESS;
  }

Classification:

ANSI, POSIX 1003.1

Safety:
Cancellation point No
Interrupt handler No
Signal handler Read the Caveats
Thread Yes

Caveats:

It's safe to call vsprintf() in a signal handler if the data isn't floating point.

See also:

fprintf(), fwprintf(), printf(), snprintf(), sprintf(), swprintf(), va_start(), vfprintf(), vfwprintf(), vprintf(), vsnprintf(), vswprintf(), vwprintf(), wprintf()


Warning: main(/www/www/htdocs/style/footer.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/neutrino/lib_ref/v/vsprintf.html on line 186

Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/footer.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/neutrino/lib_ref/v/vsprintf.html on line 186