You can't do that in C, the language doesn't support such a construct.
You can often solve this exact type of problem using variable-arguments functions again:
void getInput(const char *request, const char *fmt, ...)
{
va_list args;
printf("%s: ", request);
fflush(stdout);
va_start(fmt, args);
vscanf(fmt, args);
va_end(args);
}
Usage is like this:
int main(void)
{
double input;
getInput("Input", "%lf", &input);
return 0;
}
Of course you might want to add proper return-value handling, otherwise it's impossible to know if the embedded vscanf()
succeeded so the variable is OK to use.