How is "vsprintf()" used in C++?
Type | Description |
c | Character |
d or i | Signed decimal integer |
e | Scientific notation using e character |
E | Scientific notation using E character |
f | Decimal floating point |
g | Use the shorter of %e or %f |
G | Use the shorter of %E or %f |
o | Signed octal |
s | String of characters |
u | Unsigned decimal integer |
x | Unsigned hexadecimal integer |
X | Unsigned hexadecimal integer(capital) |
p | Pointer address |
% | A % followed by another % character will write % to the stream. |
#include <stdarg.h> #include <stdio.h> void vsform (char *string, char *format, ...); char arr [] = "%s %s %s\n"; int main(void) { char string[100]; vsform(string, arr , "A", "B", "C"); printf("The strings are: %s\n", string); } void vsform(char *string, char *fmt, ...) { va_list arg_ptr; va_start(arg_ptr, fmt); vsprintf(string, fmt, arg_ptr); va_end(arg_ptr); } |