Can someone explain how to use Ellipsis ( ... ) operator? I found a very short explanation in the help file which is I can not understand how to use it to create a variable number argument function. Here is what I found in the help file :
Ellipsis ('...') Operator
An ellipsis ('...') consists of three successive periods with no whitespace intervening. You can use an ellipsis in the formal argument lists of function prototypes to indicate a variable number of arguments, or arguments with varying types. For example:
void func (int n, char ch, ...);
This declaration indicates that func will be defined in such a way that calls must have at least two arguments, an int and a char, but can also have any number of additional arguments.
Example:
#include <stdarg.h>
int addvararg(char a1,...){
va_list ap;
char temp;
va_start(ap,a1);
while( temp = va_arg(ap,char))
a1 += temp;
return a1;
}
int res;
void main() {
res = addvararg(1,2,3,4,5,0);
res = addvararg(1,2,3,4,5,6,7,8,9,10,0);
}//~!