Home > front end >  a parameter list with an ellipsis can't match an empty parameter name list declaration
a parameter list with an ellipsis can't match an empty parameter name list declaration

Time:10-15

Please I don't know why I get "a parameter list with an ellipsis can't match an empty parameter name list declaration" when I run the code below. I believe I did everything right but my gcc compiler is given me that error.

#include <stdarg.h>

/**
 * main - check the code
 *
 * Return: Always 0.
 */

int main(void)
{
  int sum;

  sum = sum_them_all(2, 98, 1024);
  printf("%d\n", sum);
  sum = sum_them_all(4, 98, 1024, 402, -1024);
  printf("%d\n", sum);    
  return (0);
}

/**
 * @sum_them_all - calculate the entire sum. 
 * 
 * @n: constant int param signifiying the total num to sum 
 * @... - ellipsis (other params)
 * 
 * Return: the sum
 */

int sum_them_all(const unsigned int n, ...)
{
  unsigned int i;
  va_list ag;
  unsigned int sum = 0;

  va_start(ag, n);

  for (i = 0; i < n; i  )
  {
    sum  = va_arg(ag, int);  
  }

  va_end(ag);
  return (sum);
}```

CodePudding user response:

You can solve this in one of two ways. First, you could move the main function after your sum_them_all function so that the compiler knows how to utilize this function. Second, you could add a function prototype at the beginning of your code before the function is called.

int sum_them_all(const unsigned int, ...);

Either way should resolve your issue.

  •  Tags:  
  • c
  • Related