printf function Source Code implementation

Source: Internet
Author: User

#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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.