int myprintf(const char *format,...) { va_list arg; int strlen; char str[200]; va_start(arg, format); strlen = vsprintf(str,format, arg); //将数据填入str中,并返回str大小 va_end(arg); printf("myprintf len:%d,str:%s ",strlen,str); return strlen; } int main() { myprintf("%s,%s","123","456"); myprintf("%s,%.2f %.2f %d","123",12.35,5.555,120); return 0; }
打印如下: