You are here:

C/how to use va_list

Advertisement


Question
in example u r showing, no of arguments mentioned explicitely in the first argument.

is it not possible to aviod that also.
i want to avoid that.

-------------------------
Followup To
Question -
hello,

just i want to write a program which can take unknown number of integers and sum these numbers using va_list,va_arg...

but, i am not able to recognize the last element in series.can u help in this regard.

i want a generalized program , i dont want to terminate my series with 0 or any other pre-determined number.

u just tell me how can i recognize the last element.
i hv seen at the va_list example given in Turbo C help,but they r using 0 for end of numbers.




Answer -
Here is a link which might help:
http://www.cprogramming.com/tutorial/lesson17.html

-ssnkumar

Answer
YES. The first argument is a char pointer, which inturn contains the link to number of arguments.
This is the only way to use VA_LIST.
If you want to try other methods, then you can try sending a linked list, which ends with a NULL.
Upon seeing NULL you can decide that it is the end of input.

-ssnkumar

C

All Answers


Answers by Expert:


Ask Experts

Volunteer


Narendra

Expertise

I can answer questions in C related to programming, data structures, pointers and file manipulation. I use Solaris for doing C code and if you have questions related to C programming on Solaris, I will be able to help better.

Experience

6.5

Organizations belong to
Sun Microsystems

Awards and Honors
Brain Bench Certified Expert C programmer.
Advanced System Software Certified

©2012 About.com, a part of The New York Times Company. All rights reserved.