If I want to print something like "Hello" onto my Serial monitor I instead get a certain length of my character array variable instead. Also my integer variables are changing to values that I do not recognize at all.
The issue is coming from using the length() function. But I do not know why.
I want to use this method to convert a string that is input from a user and convert it to a charArray as I then want to save into EEPROM using the EEPROMex library. But this issue is stopping me from going any further.
Here is my code( I am not getting any errors or warnings using this code:
int address = 1;
int input = 2;
int output = 3;
String inputString = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
unsigned int len = inputString.length() + 1;
char addrChar[] = "a";
void setup() {
inputString.toCharArray(addrChar, len);
Serial.begin(9600);
Serial.println("address: ");
Serial.println(address);
Serial.println("Hello ");
Serial.println(" ");
Serial.println("output: ");
Serial.println(output);
Serial.println("Goodbye: ");
Serial.println(" ");
Serial.println("CharArray: ");
Serial.println(addrChar);
Serial.print("Length of CharArray: ");
Serial.println(inputString.length() + 1);
}
Here is what is printed out onto my serial monitor:
GHIJKLMNOPQRSTUVWXYZ
17989
QRSTUVWXYZ
XYZ
17475
Goodbye:
CharArray;
ABCDEFGHIJKLMNOPQRSTUVWXYZ
Length of CharArray: 27
Why is this happening? Can it be fixed? If so, how? If not, what other/better method can I use to convert a string to a character array?