This shows you the differences between two versions of the page.
— |
c:stdio.h:vprintf [2024/02/16 01:05] (current) |
||
---|---|---|---|
Line 1: | Line 1: | ||
+ | {{keywords>wiki library source code example reference}} | ||
+ | ====== vprintf ====== | ||
+ | |||
+ | <code c> | ||
+ | int vprintf(const char *format, va_list arg); | ||
+ | </code> | ||
+ | Equivalent to printf with variable argument list replaced by arg, which must have been initialised by the va_start macro (and may have been used in calls to va_arg).\\ | ||
+ | is used to generate a string from a format string and then print to standard output stdout. | ||
+ | **vprintf** can understood as a combination of [[c:stdio.h:puts|]] and [[c:stdio.h:vsprintf|]]. | ||
+ | |||
+ | ===== C Sourcecode Example ===== | ||
+ | <code c> | ||
+ | /* | ||
+ | * vprintf example code | ||
+ | * http://code-reference.com/c/stdio.h/vprintf | ||
+ | */ | ||
+ | |||
+ | #include <stdio.h> /* including standard library */ | ||
+ | //#include <windows.h> /* uncomment this for Windows */ | ||
+ | |||
+ | #include <stdarg.h> /* included for va_list */ | ||
+ | |||
+ | int myprintf( char const * format, ... ) | ||
+ | { | ||
+ | va_list args; | ||
+ | int n; | ||
+ | |||
+ | printf("vprintf example :"); | ||
+ | va_start( args, format ); | ||
+ | n = vprintf( format, args ); | ||
+ | va_end( args ); | ||
+ | |||
+ | return n; | ||
+ | } | ||
+ | |||
+ | int main ( void ) | ||
+ | { | ||
+ | char string[] ="Hello"; | ||
+ | |||
+ | myprintf( " %s World\n", string); | ||
+ | |||
+ | return 0; | ||
+ | } | ||
+ | |||
+ | </code> | ||
+ | |||
+ | ==== output ==== | ||
+ | |||
+ | |||
+ | output: ./vprintf | ||
+ | vprintf example : Hello World | ||