#include <stdio.h>
#include <stdarg.h>
int demo(char *msg, ...)
{
va_list argp;
int num = 0;
char *para;
va_start(argp, msg);
while(1) {
para = va_arg(argp, char *);
if (strcmp(para, "\0") == 0)
break;
printf("parameter #%d is: %s\n", num, para);
num++;
}
va_end(argp);
return 0;
}
int main()
{
demo("DEMO","this","is","a","demo","\0");
return 0;
}
说明:va_start(va_list类型参数, 最后一个确定参数)
va_arg(va_list类型参数, 类型参数)
va_end(va_list类型参数)
程序运行结果:
[img]http://dl.iteye.com/upload/attachment/507492/0e3eee30-bde2-38f2-b395-235fc9782b9c.bmp[/img]