带输入参数的函数用法
代码
//带参数的函数用法
#include<stdarg.h>
#include<stdio.h>
void function(char *p,...)
{
char text[256];
va_list ap;
va_start(ap,p); //获取参数
vsprintf(text,p,ap);
va_end(ap);
puts(text);
}
int main()
{
int a=10,b=45;
function("hello world %d %d\n",a,b);
return 0;
}
#include<stdarg.h>
#include<stdio.h>
void function(char *p,...)
{
char text[256];
va_list ap;
va_start(ap,p); //获取参数
vsprintf(text,p,ap);
va_end(ap);
puts(text);
}
int main()
{
int a=10,b=45;
function("hello world %d %d\n",a,b);
return 0;
}