Function declaration with strings

I am writing code to communicate with a stepper controller via the Ethernet shield. I am successful at defining the client and doing basic send message/get reply. Now I would like to write a function that would do all of this for me.

In pseudo-code fashion, here's how I would like the function to look:

motor_reply = motor_cmd("X1000");

motor_cmd() would be called with a string "X1000" and the reply would be returned to motor_reply (which will also be a string). I'm struggling with knowing what, and how, to pass. I'm sure there is more than one way to skin this cat. A solution may even be to pass a pointer to the function containing the 'command string' and returning the reply as a pointer to a reply sting...... Any advice would be appreciated. Thank you

The input argument is a char *

someReturnType motor_cmd(char *input)
{
}

Now, the return type could be a challenge. If the motor_cmd function is dynamically allocating space to hold the output, the return type could be char *, too. However, the caller is then responsible for freeing the pointer when done with it.

It is usually better to pass the address of the array to write to to the function:

void motor_cmd(char *input, char *output)
{
}

Then call it:

char buffer[48]; // Or whatever size is needed
motor_cmd("X1000", buffer);
char* motor_cmd ()
{
   static char buffer[50];
   return buffer;
}

or

static char buffer[50];
char* motor_cmd ()
{   
   return buffer;
}
static char buffer[50];
char* motor_cmd ()
{   
   return buffer;
}

If buffer is declared outside the function, it is global. What use is it to return a pointer to a global variable?

PaulS:
If buffer is declared outside the function, it is global. What use is it to return a pointer to a global variable?

It's one way to have the callee not be responsible for freeing the memory. It is a global variable but the static keyword makes the compiler not export the variable in the object file. In other words, it is global to only the functions in the same compilation/translation unit.