vsprintf, vswprintf

De RAD Studio
Aller à : navigation, rechercher

Remonter à Stdio.h - Index


Header File

stdio.h

Category

Memory and String Manipulation Routines

Prototype

int vsprintf(char *buffer, const char *format, va_list arglist);

int vswprintf(wchar_t *buffer, const wchar_t *format, va_list arglist);

Description

Writes formatted output to a string.

The v...printf functions are known as alternate entry points for the ...printf functions. They behave exactly like their ...printf counterparts, but they accept a pointer to a list of arguments instead of an argument list.

vsprintf accepts a pointer to a series of arguments, applies to each a format specifier contained in the format string pointed to by format, and outputs the formatted data to a string. There must be the same number of format specifiers as arguments.

Return Value

vsprintf returns the number of bytes output. In the event of error, vsprintf returns EOF.

Example

#include <stdio.h>
#include <conio.h>
#include <stdarg.h>
char buffer[80];
int vspf(char *fmt, ...)
{
   va_list argptr;
   int cnt;
   va_start(argptr, fmt);
   cnt = vsprintf(buffer, fmt, argptr);
   va_end(argptr);
   return(cnt);
}
int main(void)
{
   int inumber = 30;
   float fnumber = 90.0;
   char string[4] = "abc";
   vspf("%d %f %s", inumber, fnumber, string);
   printf("%s\n", buffer);
   return 0;
}

Portability

POSIX Win32 ANSI C ANSI C++

vsprintf

+

+

+

+

vswprintf

+

+

+


See Also