va_copy - C stdarg.h

C examples for stdarg.h:va_copy

type

macro

From

<cstdarg>

Description

Copy variable argument list

Prototype

void va_copy (va_list dest, va_list src);

Return Value

none

Demo Code


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>

int getArgumentCountTillZero(int first, ...)
{
  int count = 0;/*from  w  w w  . j a va  2  s.  co m*/
  int val = first;
  va_list vl, vl_count;
  va_start(vl, first);

  /* count number of arguments: */
  va_copy(vl_count, vl);

  while (val != 0) {
    val = va_arg(vl_count, int);
    ++count;
  }
  va_end(vl);
  return count;
}

int main()
{
  printf("%d", getArgumentCountTillZero(10, 20, 30, 40, 50, 0));
  return 0;
}

Related Tutorials