Note that there are some explanatory texts on larger screens.

plurals
  1. POArduino - Comparing a split string with another string
    primarykey
    data
    text
    <p>I'm trying to compare an exploded string to another string in Arduino, but it won't work. The string that is split is read from the serial port.</p> <p>First of all, these are the functions I use for exploding the string:</p> <pre><code>int count_delimiters(char str[], const char* delimiters) { int i, j, result = 0; for (i = 0; i &lt; strlen(str); ++i) { for (j = 0; j &lt; strlen(delimiters); ++j) { if (str[i] == delimiters[j]) { ++result; } } } return (result + 1); } char** split(char str[], const char* delimiters) { int result_size = count_delimiters(str, delimiters); int i = 0; char* result[result_size]; char* pch = strtok(str, ","); while (pch != NULL) { result[i] = pch; pch = strtok(NULL, ","); ++i; } return result; } </code></pre> <p>The part where I try to compare the exploded string to another string looks like this:</p> <pre><code>char input_array[input.length()]; input.toCharArray(input_array, (input.length() + 1)); exploded = split(input_array, ","); if ("$test" == exploded[0]) { Serial.println("match"); // This code is never reached. } </code></pre> <p>When I enter <strong>$test,other</strong> in the serial monitor I expect a match to be printed out but nothing is printed. If I do <code>Serial.println(exploded[0]);</code> it outputs <strong>$test</strong> as it should. What am I doing wrong?</p> <p>I've already tried to look for non-printable characters like <code>\r</code>, <code>\n</code> and <code>\0</code>, but it doesn't seem to contain any of these, because when I check for "$test\r" or the others it still doesn't return true.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload