下面的代码有什么问题?怎样才能让print()函数像printf一样工作?
#include <stdio.h>
#include<stdarg.h>
void print(char *format,...)
{
va_list args;
va_start(args,format);
printf(format,args);
}
int main() {
print("%d %s",5,"le");
}发布于 2012-05-21 23:59:01
这里需要vprintf。看看这个问题,它有一个类似的问题:what's the difference between the printf and vprintf function families, and when should I use one over the other?
发布于 2012-05-21 23:58:23
如果您需要传递varargs,那么请使用vprintf。
发布于 2012-05-21 23:58:15
您可能需要查看vprintf。该函数(以及相关函数)允许您传递变量参数列表,并由它们处理格式化。
https://stackoverflow.com/questions/10688522
复制相似问题