#include <stdio.h> #include <stdarg.h>//va_start (Arg,format), initialize the parameter pointer arg, Assigning the first parameter address to the right of the function parameter to Arg//format must be a pointer to a parameter, so that the type function should have at least one common parameter, //thereby providing to va_start Va_ Start to find the position of the mutable parameter on the stack. //va_arg (Arg,char), gets the value of arg pointing to the parameter, while Arg refers to the next argument, char is used to nominate the current parameter type//va_end in some implementations may change arg to an invalid value, here, the ARG pointer is pointed to the null, avoid the presence of wild hands void print (const char *format, ...) {Va_list arg;va_start (Arg, format);while (*format) {char ret = *format;if ( ret == '% ') {switch (*++format) {case ' C ': {Char ch = va_arg (Arg, char); Putchar (ch); break;} case ' s ': {char *pc = va_arg (arg, char *);while (*pc) {Putchar (*pc);p C + +;} break;} Default:break;}} Else{putchar (*format);} format++;} Va_end (ARG);} Int main () {print ("%s %s %c%c%c%c%c!\n", "Welcome", "to", ' C ', ' h ', ' I ' , ' n ', ' a '); System ("pause"); return 0;}
650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M02/76/5A/wKioL1ZQfY2hQOOGAAAZkTUFq_w029.png "title=" 360 Feedback 164901296072105.png "alt=" Wkiol1zqfy2hqoogaaazktufq_w029.png "/>
printf function Source Code implementation