Variable Argument Functions[QUESTION]
#1

How to do this in PAWN?

Код:
int Numbers::addNumbers(int n, ...)
{
	va_list args;
	int sum = 0;
	va_start(args, n);
	for (int x=0; x<n; x++)
	{
		sum += va_arg(args, int);
	}
	va_end(args);
	return sum;
}
Reply
#2

pawn Код:
stock addNumbers(n, ...)
{
    new args = numargs();
    new sum = n;
    for(new i;i<args;i++)
    {
        sum += getarg(i,0);
    }
    return sum;
}
not sure.. should be it
Reply
#3

Remove the n and you should be fine

pawn Код:
stock addNumbers(...) {
    new
        sum = 0,
        num = numargs();
    while(--num != -1) {
        sum += getarg(num, 0);
    }
    return sum;
}
Reply
#4

Thank you both. Deserve reputation.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)