#include<stdarg.h> #include<stdlib.h> #include<stdio.h>
void minprintf(char * fmt,...); void test(int a,int b,int c);
int main() { // minprintf("num=%d,double=%f,string=%s\n",12,12.11,"ss");
minprintf("str=%s","abc"); test(1,2,3); }
void test(int a,int b,int c) { printf("%d,%d,%d\n",a,b,c); }
void minprintf(char * fmt,...) { va_list ap; char *p, *sval; int ival; double dval; va_start(ap,fmt); 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); }
|