Talking about variable parameters in C Language

Source: Internet
Author: User
In my previous blog post (exploring the function of variable parameters in C language), I introduced the principle of variable parameters in C language and a simple example. However, I found that the example is not very good, I found a better example today.

 # include 
  
   /* minprintf: Minimal printf with variable argument list */void minprintf (char * FMT ,...) {va_list AP;/* points to each unnamed ARG in turn */char * P, * sval; int ival; double dval; va_start (AP, FMT ); /* Make AP point to 1st unnamed Arg */For (P = FMT; * P; P ++) {If (* P! = '%') {Putchar (* P); continue;} switch (* ++ p) {Case 'D': ival = va_arg (AP, INT ); printf ("% d", ival); break; Case 'F': dval = va_arg (AP, double); printf ("% F", dval); break; case's ': For (sval = va_arg (AP, char *); * sval; sval ++) putchar (* sval); break; default: putchar (* P ); break ;}} va_end (AP);/* clean up when done */} 
  

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.