In the future, learn to use code tags (hit the '#' button), it helps people read your code.
Your problem is the tmp declaration is on the stack. When you return, the stack is erased, and Serial.println will overwrite it. I would suggest declaring it as:
static char tmp[128]; // resulting string limited to 128 chars
This says to put tmp in static storage which does not change between function invocations.
MichaelMeissner:
In the future, learn to use code tags (hit the '#' button), it helps people read your code.
Good call - I will keep it in mind.
MichaelMeissner:
Your problem is the tmp declaration is on the stack. When you return, the stack is erased, and Serial.println will overwrite it. I would suggest declaring it as:
Thanks but it does not fix the issue.
I think it may have something to do with passing a String to the function P
If I pass a constant string "CHRIS" then it works as expected, but if I put "Chris" into a String and pass that the function returns no data and for all I know never returns.
iisfaq:
If I pass a constant string "CHRIS" then it works as expected, but if I put "Chris" into a String and pass that the function returns no data and for all I know never returns.
Any other ideas?
You can't pass String types to *printf functions. It does not know about the String type. Instead you have to convert String back to a char array, and pass that to your function and use %s with it.
MichaelMeissner:
You can't pass String types to *printf functions. It does not know about the String type. Instead you have to convert String back to a char array, and pass that to your function and use %s with it.
After reading this i found that I could simply change my array and it is all happy now