Back to index

glibc  2.9
add.c
Go to the documentation of this file.
00001 #include <stdarg.h>
00002 #include <stdio.h>
00003 
00004 int
00005 add_em_up (int count,...)
00006 {
00007   va_list ap;
00008   int i, sum;
00009 
00010   va_start (ap, count);            /* Initialize the argument list. */
00011 
00012   sum = 0;
00013   for (i = 0; i < count; i++)
00014     sum += va_arg (ap, int);       /* Get the next argument value. */
00015 
00016   va_end (ap);                     /* Clean up. */
00017   return sum;
00018 }
00019 
00020 int
00021 main (void)
00022 {
00023   /* This call prints 16. */
00024   printf ("%d\n", add_em_up (3, 5, 5, 6));
00025 
00026   /* This call prints 55. */
00027   printf ("%d\n", add_em_up (10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10));
00028 
00029   return 0;
00030 }