I'm quite new to Arduino programming but am totally hooked . What I thought would be an easy challenge has proven problematic. I've done lot's of reading, learnt loads about memory allocation, pointers, addresses and null pointers. However I still come up against a brick wall.
In the simplest terms I need to return a substring from a string, not from the String class but from char. Have tried a dozen different inventive ways without success.
Latest attempt was part inspired from Copy part of a char* to another char* - Programming Questions - Arduino Forum
char myChar[] = "Hello Mum";
void setup() {
 Serial.begin(9600);
 char returnChar[3]; //Char to store sub string 0-4 i.e. 4 elements
 char * ptrMum = strchr(myChar, "M"); //Pointer to address of "M" in "Hello Mum"
 strncpy(returnChar, ptrMum, 3); //Copy in to returnChar, from the pointer, copy 3 characters
 returnChar[3] = '\0'; //Put a null pointer at array 3
 Serial.print("This is the result ");
 Serial.println(returnChar); //Returns This is the result with followed by a square box
}
void loop(){
}
In this example I'm using strchr to get the pointer of capital "M" in myChar.
I then use strncopy to copy 3 elements of that array into returnChar.
However when I output to the serial port I get a reverse question mark or box.
Can someone put me out of my misery by switching the light on?
Thanks in advance.