Error handling strings and chars
toCharArray is alias for getBytes. getBytes is documented as "Copies the String’s characters to the supplied buffer." You did not allocate the memory for the copied characters.

the right use of 'getBytes' and 'toCharArray' is

char buffer[BUFF_SIZE];
str.getBytes(buffer, sizeof[buffer]);


note: getBytes functions sets the terminating zero of the c-string in buffer