Not really. You'll want to make a few adjustments:
Code:
file one:
...
char ret[32];
...
getMechStatus(ret); /* but you'd already made this change */
file two:
void getMechStatus(char ret[])
{
...
...
/* you no longer want this: return ret; */
}
Please keep in mind that you're passing to
getMechStatus() not the full 32 bytes, but a pointer to them. As a reminder, most people would probably say
Code:
void getMechStatus(char *ret)
Say this inside
getMechStatus():
Code:
printf("%d\n",sizeof(ret));
and you'll see what I mean.
Also, it's up to you to make sure that
getMechStatus() stays within the 32 bytes of the array. Obviously, you can't use
sizeof() within
getMechStatus() to help you.
getMechStatus() has no inherent way to test the size of the array.
Also, please keep in mind that the global
ret and the parameter
ret within
getMechStatus() are two separate creatures; the following code would act identically, and most people would probably code two separate names to remind them of this.
Code:
file one:
...
char fred[32];
...
getMechStatus(fred); /* but you'd already made this change */
file two:
void getMechStatus(char barney[])
{
/* code within this function refers to barney, not fred
...
...
/* you no longer want this: return ret; */
}