]> git.donarmstrong.com Git - biopieces.git/commitdiff
added a variable argument list example to c scr
authormartinahansen <martinahansen@74ccb610-7750-0410-82ae-013aeee3265d>
Sun, 20 Jul 2008 23:50:53 +0000 (23:50 +0000)
committermartinahansen <martinahansen@74ccb610-7750-0410-82ae-013aeee3265d>
Sun, 20 Jul 2008 23:50:53 +0000 (23:50 +0000)
git-svn-id: http://biopieces.googlecode.com/svn/trunk@173 74ccb610-7750-0410-82ae-013aeee3265d

code_c/Maasha/src/inc/common.h
code_c/Maasha/src/test.c

index 073e3afbd4b4b9fa9b994b7eeb0d90b572e9c5f5..fcc01bf2b0f557530505928f810f03074c0672e0 100644 (file)
@@ -1,6 +1,7 @@
 /* Including standard libraries */
 #include <stdio.h>
 #include <stdlib.h>
+#include <stdarg.h>
 #include <string.h>
 #include <unistd.h>
 #include <ctype.h>
index 7a141d5aa49bf7b6c747e943272c5e39d9debd8f..f7ed89e9be078b0704bdd7c0c52e1d0866bdd1d8 100644 (file)
@@ -24,6 +24,33 @@ int main( int argc, char *argv[] )
 }
 
 
+double avarage( int num, ... )
+{
+    /* Martin A. Hansen, July 2008 */
+
+    /* Example of varable length argument list usage. */
+
+    /* Requires '#include <stdarg.h>' */
+
+    double sum = 0;
+    int    x   = 0;
+
+    va_list arguments;
+
+    va_start( arguments, num );
+
+    for ( x = 0; x < num; x++ )
+    {
+        sum += va_arg( arguments, double );
+    }
+
+    va_end( arguments );
+
+    return sum / num;
+}
+
+
+
 /*
 
 int main( int argc, char *argv[] )