Paul nailed your problem and GoForSmoke has sage advice...the String class is from C++ and is usually an H-bomb-to-kill-an-ant approach to text processing. Your code could be replaced with something like:
void setup() {
char buffer[20]; // I have no idea how big you need this, I just made one up...
char input[20];
char *ptr;
ptr = SplitCommand(input, splitChar, buffer);
// Whatever you need to do...
}
char *splitCommand(char *text, char splitChar, char buffer[]) {
int splitCount = countSplitCharacters(text, splitChar);
int index = -1;
int index2;
for(int i = 0; i < splitCount - 1; i++) { // Not sure this is what you really want...
index = text.indexOf(splitChar, index + 1);
index2 = text.indexOf(splitChar, index + 1);
if(index2 < 0)
index2 = text.length() - 1;
buffer[i] = text.substring(index, index2);
}
return buffer;
}
(I didn't check to see if your code is doing what you think it should...only the syntax structure of the code.)
The first line of the function definition:
char *splitCommand(char *text, char splitChar, char buffer[]) {
is broadly built of two parts: 1) the function type specifier, which tells the type of data returned from the function, a char pointer (char *) in this example, and 2) the function signature, which extends from the start of the function name through the closing parenthesis (i.e., splitCommand(char *text, char splitChar, char buffer[]) ) As Paul pointed out, your function type specifier was wrong, because you cannot return an array from a function. You can, however, return a pointer to it which is what I've done here. Not returning an array makes sense if you think about it, because the compiler would have to copy the entire array onto the stack when the function code was done, and then pop it off the stack when it returned. This would unnecessarily take time and memory.
Also note in the signature that char *test could be written as char test[], as I did for buffer. Also, an array name, like buffer is viewed by the compiler as though you wrote it &buffer[0]. That is, the array name is the same as the memory address for the first element of the array.