In CAPL, apparently you cannot pass a string as an input parameter for a user-defined function, according to the docs (see CAPL Introduction » Data Types for Function Parameters).
I'm working with file handling, both in read and write directions. I'd like to refactor my code to use a function that accepts the filename as input parameter.
Apart from the obvious workarounds, such as using a global variable, using a system/environment variable, I'm interested in the possibility of other alternatives.
How do you do it?
edit
CAPL does not provide the string type, much like C these are "just" arrays of characters.
In the help page I was mentioning, you can pass a single char as parameter function, but not a char[] array.
What, rightfully, mr. Spiller points out is that this piece of code works:
on start
{
function("a string");
}
void function(char string[])
{
write ("my string is %s", string);
}
and outputs:
CAPL / .NET my string is a string
However, that looks like an associative array to me.
For instance, this compiles as well:
void function(int number[], char string[])
{
// do stuff
}
But understanding what is going on is suddenly more difficult, as this won't compile:
on start
{
function(13, "a string");
}
void function(int number[], char string[])
{
write ("my number is %d", number);
write ("my string is %s", string);
}
Error: types of parameters do not match.
Finally:
variables
{
int associativeArray[ float ];
}
on start
{
associativeArray[1] = 3;
function(associativeArray, "a string");
}
void function(int number[float], char string[])
{
for (float aKey: number)
{
write ("my number is %d(%f)", number[aKey], aKey);
}
}
CAPL / .NET my number is 3(1.000000)
works as intended, but then again, I'm unsure of what the caveats of using an associative array are in this scenario (I can't find out a way of iterate over the string with the same syntax, for instance), and how do you address them, if you do.