C Standard Libraries C++

vsprintf()

Declaration

int vsprintf(char* cpBuffer, const char* kcpFormatString, va_list qVarArgList);

Description

This function writes the null-terminated formatted string defined by "kcpFormatString" and its arguments "qVarArgList" into the buffer "cpBuffer." If successful, the function returns the number of characters that were written, not including the terminating NULL. Otherwise, the function returns a negative value to indicate that an error occurred.

Example

#include <cstdio>
#include <cstdarg>

void PutArgsInBuffer(char* cpBuffer, char* cpFormat, ...)
{
    va_list qVarArg = 0;
    va_start(qVarArg, cpFormat);

    // Put the arguments into the buffer
    vsprintf(cpBuffer, cpFormat, qVarArg);

    va_end(qVarArg);
}

int main()
{
    char caBuffer[100];
    PutArgsInBuffer(caBuffer, "%s %d", "XoaX.net", 2009);

    printf("Buffer Holds: %s\n", caBuffer);

    return 0;
}

Output

vsprintf() Output
 

© 2007–2024 XoaX.net LLC. All rights reserved.