Garmaine Staff asked 1 year ago

I am new to Arduino, and haven't done any C++ for almost a decade. So here my really basic question:

I want to make a function that can return two strings, for that i was thinking in passing the strings by reference. Something like this:

void return_array_byref((char[]) & device, (char[]) & command) 
{
    device = malloc(8 * sizeof(char));
    device[0] = 'C';
    device[1] = '\n';

    command= malloc(8 * sizeof(char));
    command[0] = 'C';
    command[1] = '\n';
}

void loop() {
    char * device;
    char * command;
    return_array_byref(device, command);

    ...
}

I have tried using char **, char[] &, char * & but nothing seems to work. With the code above I am getting this:

arduino:6:25: error: variable or field 'return_array_byref' declared void

 void  return_array_byref((char[]) & device)

                         ^

What is the right way of doing this in C++?