Well, let me explain by taking your code example.

In your code you have written this line.

int x = total(0,1,2,3,4,5,6,7,9,10,11,12,0);

here y0u have given the numbers which you liked.

My question is: Instead of you giving the numbers is there any way to accept those numbers at runtime from the user and pass the same to tal function.

Well this is the output I am expecting on running:

OUTPUT

Enter the numbers you want to add separated by comma:
1,2,3,4

The Total is 10

My problem is: I want to call the method, but I don't know at compile-time which arguments I want to pass.Is there some way by which I can create the va_list during run time and pass it to the fucntion.

Eg Code:
total(4, 1,2,3,4) ;//Where 4 is the number of arguments and 1,2,3,4 is my va_list;

[CODE]int total( int numargs, ... )
{

int sum = 0;
int i ;

int arg;

va_list listpointer;
va_start(listpointer,numargs);
//printf(" The numarg value is %d\n",numargs);

while(arg!= 0)
{
arg = va_arg(listpointer,int);

//printf(" The arg returned %d",arg);

sum += arg;

}

va_end(listpointer);

printf("Total Purchase amount = %d\n", sum);
return sum;

}[/CODE]

the above works fine and gives me a correct output.

But, as you can see I am defining the va_list during compile time only but not in run time.Is there an elegant way to accept the arguments in runtime and pass it to the total function at runtime and it would add up and show the result.

Thanks
Sumit