sprintf()

Declaration

int sprintf(char* cpBuffer, const char* kcpFormatString, ...);

Description:

This function writes the null-terminated formatted string defined by "kcpFormatString" and its arguments into the buffer "cpBuffer." If successful, the function returns number of bytes put into the buffer, excluding the null terminator. Otherwise, the function returns -1 to indicate an error.

Example

#include <cstdio>

int main()
{
    char caBuffer[100];
    // Fill the buffer with a formatted string.
    sprintf(caBuffer, "XoaX%s\n", ".net");

    // Output the buffer's contents 
    printf("Buffer holds: %s\n", caBuffer);

    return 0;
}

Output:

sprintf() Output