NEED HELP NOW!

C2. Functions with variable number of arguments
Write a function write with variable number of arguments that takes a string first argument followed by any number of arguments of type double and prints on the screen a string formatted by the rules described below. The first argument may contain formats in curly braces of the form {index[:specifier]}, where the square brackets show optional parts (this is :specifier may be missing), and index is the sequence number of an argument of type double (starting from sequence number 0).
Rules for formatting: In the printed string the curly brackets and their content will be replaced by the argument with the given index, formatted according to the given format specifier. If the format specifier is missing, the argument will be printed with its default format. For example:
write("The number {0} is greater than {1}.", 5, -3);
will print
The number 5 is greater than -3.
write("There are no format specifiers here.");
will print
There are no format specifiers here.

I'm really lost on how to complete this program. How does one create a string for a specifier?? and then include the arguments within the string?? Thank you.
the string inside write is your format specifier string.
number is curly braces are argument index, starting from zero. anything separated by commas after the string are the argument for the format

so in write("The number {0} is greater than {1}.", 5, -3);
{0} is replaced by argument at index 0, which is 5; {1} is replaced by argument at index 1, which is -3
So are what you are saying is that the number of arguments is declared by the number of {} in the string?
I'm still confused on how to create this, if you could possibly show me parts to set this up it would be much appreciated.
I'm working on the same problem. Cant for the life of me figure out how to do this.
No the number of arguments. the index of arguments is represented by the number in {}.

The number of {} in the string should match number of arguments after the string

example
write("The number {0} is greater than {1}.", 5, -3); has two {} hence two arguments (5, -3) after string

write("The number {0} is considered a positive number.", 0); in this case there is only one pair of {} so there is only one argument after format string. Also, zero in {} indicates that '{0}' should be replaced by the argument at index zero

Hope this clarifies things.

If you want to implement this in C then look at http://publications.gbdirect.co.uk/c_book/chapter9/stdarg.html

in C++ look at (a bit advance level) http://www.cplusplus.com/articles/EhvU7k9E/
Topic archived. No new replies allowed.