Is there any way to construct an array of strings inside a function call? For example, say I have a function like this:
void foo( char * [] strings )
{
//...does stuff
}
And instead of declaring the character array first and then passing it, is there any way, with arrays or any other container class, to call the function like this?
foo( { "a", "b", "c", ...} );
Basically I have a function that prompts a user for input until it matches one of the strings in the array I pass, and since that changes throughout the program, I pass the accepted inputs into the function that prompts the user and validates the input. Currently I am just constructing it outside the function and passing it in but was wondering if they could be combined into one line in any way
This works in C99:
Since you mention “container” you probably use
C++so this answer is of limited value (unless you are using a compiler that accepts it as an extension – the way GCC does for example).