From: martinahansen Date: Sun, 20 Jul 2008 23:50:53 +0000 (+0000) Subject: added a variable argument list example to c scr X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=b9007484c4d5cdd3232f3a42ce00882053782f99;p=biopieces.git added a variable argument list example to c scr git-svn-id: http://biopieces.googlecode.com/svn/trunk@173 74ccb610-7750-0410-82ae-013aeee3265d --- diff --git a/code_c/Maasha/src/inc/common.h b/code_c/Maasha/src/inc/common.h index 073e3af..fcc01bf 100644 --- a/code_c/Maasha/src/inc/common.h +++ b/code_c/Maasha/src/inc/common.h @@ -1,6 +1,7 @@ /* Including standard libraries */ #include #include +#include #include #include #include diff --git a/code_c/Maasha/src/test.c b/code_c/Maasha/src/test.c index 7a141d5..f7ed89e 100644 --- a/code_c/Maasha/src/test.c +++ b/code_c/Maasha/src/test.c @@ -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 ' */ + + 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[] )