0

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.

theateist
  • 13,879
  • 17
  • 69
  • 109

1 Answers1

0

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);
}
Mateen Ulhaq
  • 24,552
  • 19
  • 101
  • 135