/* va_start example */
#include <stdio.h> /* printf */
#include <stdarg.h> /* va_list, va_start, va_arg, va_end */
void PrintFloats (int n, ...)
{
int i;
double val;
printf ("Printing floats:");
va_list vl;
va_start(vl,n);
for (i=0;i<n;i++)
{
val=va_arg(vl,double);
printf (" [%.2f]",val);
}
va_end(vl);
printf ("\n");
}
int main ()
{
PrintFloats (4,3.14159,2.71828,1.41421,8.0);
return 0;
}
Result :
Printing floats: [3.14] [2.72] [1.41] [8.00]
Reference:
1. va_start
0 意見:
張貼留言