带输入参数的函数用法

 

代码
//带参数的函数用法
#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;
}

 

 

posted @ 2010-02-08 12:24  liuweixuan  阅读(144)  评论(0编辑  收藏  举报