문제

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);
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top