-3

I am trying to write a multi input function in C programming. Could somebody explain me that what is the meaning of the 3 points in the following code example? I realize that I could use “sprintf” with 2 input or 3 or more depending of the demand. How could use this method in my programs. Thanks in advance

int sprintf (char *string, const char *form, … );
Cagri Candan
  • 90
  • 1
  • 9

1 Answers1

-3

The expression signifies that the function must have the two parameters char *string and const char *form, and the three dots signify that there could/should be more parameters.

Note: this is not correct C++ syntax the author is simply trying to communicate the fact that there could/should be more parameters, depending on what the question is asking.

In order to make the function so that it can take different combinations of parameters, you need to use function overloading. This is where you redefine the function (using the same function name and type) for each combination of parameters you want your function to be able to support.

For example, if you wanted to make your function int sprintf so that it could take a pointer to a character and a pointer to a constant character, or a pointer to a character, a pointer to a constant character and an integer you need to write two definition: one for

int sprintf (char *string, const char *form);

And one for

int sprintf (char *string, const char *form, int number);
  • `sprintf` is a standard C function and `...` is part of its prototype as shown in the question. Also this is a C question not a C++ one. – M.M May 22 '16 at 09:33