I'm trying to compare a char array that I'm assembling to a string and I'm having trouble comparing the strings.
I'm getting the data for the char array as a set of bytes and I'm compiling it into a char array like this:
void messageHandler(char *topic, byte *payload, unsigned int length)
{
char buffer[length];
for (int i = 0; i < length; i++)
{
buffer[i] = (char)payload[i];
}
So grabbing each of the ASCII codes and converting it into a character as I add it to the buffer.
After I do that I'm trying to print the buffer to the monitor and then compare it to a string. Though it's not working:
I know I'm getting all of those extra characters in the println b/c the buffer doesn't end in 0 so print keeps reading out memory bytes till it hits the zero, but I don't know why strcmp isn't showing the buffer matching the string "ravenclaw".
I'm sure it's for the same "missing the null terminator" issue, but I'm not sure how to fix it. Help is appreciated!!
