c++ - Arduino unable to match Char data -
i have arduino web server project going. right i'm trying parse url parameters. instance, wish make request http://(localip)/info , have "info" returned , displayed.
i don't know if i've been staring @ screen long today, can't seem match simple char single space... shouldn't complex in slightest! advice i've found not work. yet, need break loop on space because indicator url parameter ends. want able use /info /something else.
char *data = (char *) ethernet::buffer + pos; string buff; (int x = 5; x<15; x++) { serial.print(x); serial.print(" - |"); serial.print(data[x]); serial.println("|"); if ((data[x] == " ") || (data[x] == char(" ")) || (strcmp(data[x], " ") == 0)) { x = 999; break; } else { buff += data[x]; } delay(5); }
serial monitor output. should break on #9 , buff should equal "info"
5 - |i|
6 - |n|
7 - |f|
8 - |o|
9 - | |
10 - |h|
11 - |t|
12 - |t|
13 - |p|
14 - |/|
buff -> info http/
you using double quote marks (") in char comparisons. in c++, double quote marks used define strings, not characters. characters defined using single quotes (')
testing space: if (c == ' ')
.
unlike strings, can use chars in switch statements:
switch (c) { case 'a': case 'a': serial.println("i've got a!!"); break; }
Comments
Post a Comment