const char msg[] = "#HEAD hello mate\n1 2 3\nA B C\n";
bool checkLine(char* str, char last* = '\n', char first = NULL) {
char *cpos = strchr(str, last);
int n = (cpos-str);
if ((first != NULL) && (str[0] != first)) return false;
if (cpos) {
if (n > 32) return false;
char buf[n] = {'\0'};
strncpy(buf, str, n);
Serial.print("buf: '"); Serial.print(buf); Serial.println("'");
}
return false;
}
void myFunc(char* str, char c) {
char* ptr;
int index;
ptr = strchr(str, c);
if (ptr == NULL) return;
index = ptr - str;
Serial.print("The index is: "); Serial.println(index);
//ASSERT(str[index] == c); // Verify that the character at index is the one we want.
}
void setup() {
Serial.begin(9600);
//myFunc(msg, '\n');
checkLine(msg, '#');
while(1) delay(1);
char *p;
p = msg;
char *delim2, *delim = strchr(msg, '#');
if (delim) {
delim2 = strchr(delim, '\n');
Serial.println(delim);
Serial.println(delim2);
}
char *d2, *d = strchr(msg, '#');
if (d) {
d2 = strchr(d, ' ');
*d2 = '\0';
Serial.print("'"); Serial.print(d); Serial.println("'");
if (strcmp(*d, "#HEAD")==0)
Serial.println("MATCH!");
//*(d + strchr(d, '\n')) = '\0';
}
//p += delim;
}
void loop() {
// put your main code here, to run repeatedly:
}