Implementation of scanf functions using variable parameters in C Language
Since the printf function variable parameter is implemented, the scanf function variable parameter must be implemented. The source code is as follows:
This source code does not have much analysis. To understand the principles, please read the previous articles on this blog.
# Include
# Include
Int myscanf (const char * fmt ,...); int main (void) {int num; printf ("pls input num: \ n"); myscanf ("% d", & num); printf ("num: % d \ n ", num); return 0;} // I will not explain more about the implementation methods below. Previous blogs are very detailed and can be understood by turning them over. Int myscanf (const char * fmt ,...) {va_list ap; int ret; va_start (ap, fmt); ret = vscanf (fmt, ap); // The vscanf function of library C is called here, find it and then get it out. The analysis method is the same as that of vprintf. Va_end (ap); return ret ;}
Running result:
Input 100, output 100, input using myscanf Function