How do I return a char array from a function?
has the following code in the answers:
void testfunc(char* outStr){
char str[10];
for(int i=0; i < 10; ++i){
outStr[i] = str[i];
}
}
int main(){
char myStr[10];
testfunc(myStr);
// myStr is now filled
}
Since I will be using an Arduino where memory is precious I dont want a "temporary variable" for storing some string and then copying it over. I also don't want the function to return anything. I want to use the idea above and do something like:
void testfunc(char* outStr){
outStr="Hi there.";
}
int main(){
char myStr[10];
testfunc(myStr);
}
However, in this case myStr is empty!
Why doesn't this work? How do I fix it?
(I'm relatively new to C, and do have a basic understanding of pointers)
Thanks.