C-language variable parameter implementation scanf function

Source: Internet
Author: User

Since the printf function variable parameter is implemented, there must be a variable parameter implementation of the SCANF function. Don't say much nonsense, the source:

Source code But more analysis, such as to understand the principle, please fan Ben Blog previous articles to see the description.

Welcome to follow Sina Weibo: http://weibo.com/u/1896293701/home?topnav=1&wvr=6

#include <stdio.h> #include <stdarg.h>int myscanf (const char *FMT, ...), int main (void) {int num;p rintf ("Pls i Nput num:\n "); MYSCANF ("%d", &num);p rintf ("num:%d\n", num); return 0;} The following implementation methods I do not explain more, the previous blog is written in detail, turn over can read, not difficult. int myscanf (const char *FMT, ...) {va_list ap; int ret; Va_start (AP, FMT); ret = vscanf (FMT,AP);//The VSCANF function of C library is called here, and then it is found, and the analysis method and vprintf are identical. Va_end (AP); return ret;}
Operation Result:

Input 100, output 100, use the MYSCANF function to enter



C-language variable parameter implementation scanf function

Related Article

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.