This shows you the differences between two versions of the page.
c:stdio.h:vsprintf [2013/01/22 22:02] |
c:stdio.h:vsprintf [2024/02/16 01:05] (current) |
||
---|---|---|---|
Line 1: | Line 1: | ||
+ | {{keywords>wiki library source code example reference}} | ||
+ | ===== vsprintf ===== | ||
+ | |||
+ | <code c> | ||
+ | int vsprintf(char *str, const char *format, va_list arg); | ||
+ | </code> | ||
+ | |||
+ | generate a string from a format string. | ||
+ | For this purpose, the buffer that is passed as first argument, the format string is copied and replaces the substitution symbol with the given parameters. | ||
+ | |||
+ | ===== C Sourcecode Example ===== | ||
+ | <code c> | ||
+ | /* | ||
+ | * vsprintf example code | ||
+ | * http://code-reference.com/c/stdio.h/vsprintf | ||
+ | */ | ||
+ | |||
+ | #include <stdio.h> /* including standard library */ | ||
+ | //#include <windows.h> /* uncomment this for Windows */ | ||
+ | |||
+ | #include <stdarg.h> | ||
+ | int myprintf( char const * format, ... ) | ||
+ | { | ||
+ | va_list args; | ||
+ | int n; | ||
+ | char buffer[200]; | ||
+ | |||
+ | va_start( args, format ); | ||
+ | vsprintf( buffer, format, args ); | ||
+ | va_end( args ); | ||
+ | |||
+ | return printf("vsprintf example : %s", buffer); | ||
+ | } | ||
+ | |||
+ | int main (void) | ||
+ | { | ||
+ | char string[] ="Hello"; | ||
+ | |||
+ | myprintf( " %s World\n", string); | ||
+ | |||
+ | return 0; | ||
+ | } | ||
+ | </code> | ||
+ | |||
+ | ==== output ==== | ||
+ | |||
+ | |||
+ | output: ./vsprintf | ||
+ | vsprintf example : Hello World | ||
+ | |||