重写printf,可用作日志等相关功能。
代码:
#include <stdio.h>
#include <stdarg.h>
void My_printf(const char* fmt
,...)
{
va_list args
;
char tempbuf
[256] = {0};
va_start(args
, fmt
);
vsprintf(tempbuf
, fmt
, args
);
va_end(args
);
printf("%s\n",tempbuf
);
}
int main()
{
int count
= 0;
for(count
= 0;count
< 5;count
++)
{
My_printf("printf test %d",count
);
}
return 0;
}
测试:
转载请注明原文地址: https://lol.8miu.com/read-36911.html