How to return array from function in NXC? I tried the following
string[] strsplit(string str)
{
string parts[2] = {"1", "2"};
return parts;
}
but I get Variable name expected
. Why?
P.S. if there built-in split function I'll be glad to here about it.
string[]
cannot be a return type in C or C++, and hence NXC.
See the NXC API for SubStr()
, to help in 'splitting' strings.
Try:
void strspilt(string &out[], string str, unsigned int idx)
{
ArrayInit(out, "", 2);
out[0] = SubStr(str, 0, idx);
out[1] = SubStr(str, idx, strlen(str) - idx);
}