Hello,
while learning about using arrays of char for sequences of characters (formerly known as "strings") ;-))
I came across this democode
char TextLine[] = "MyIdentfier=98";
const char EqualSign[] = "=";
void setup() {
Serial.begin(115200);
int position = strstr(TextLine, EqualSign) - TextLine + strlen(EqualSign);
Serial.print("Number will start at position ");
Serial.println(position);
Serial.print("Number is ");
Serial.println(TextLine + position);
}
void loop() {}
out of curiosity I tried a small deviation just out-commenting
int position = strstr(TextLine, EqualSign) //- TextLine + strlen(EqualSign);
char TextLine[] = "MyIdentfier=98";
const char EqualSign[] = "=";
void setup() {
Serial.begin(115200);
int position = strstr(TextLine, EqualSign) //- TextLine + strlen(EqualSign);
Serial.print("Number will start at position ");
Serial.println(position);
Serial.print("Number is ");
Serial.println(TextLine + position);
}
void loop() {}
and then the compiler complaints
invalid conversion from 'char*' to 'int' [-fpermissive]
without the "- TextLine + strlen(EqualSign);" the value would be wrong
But How the heck can adding "- TextLine + strlen(EqualSign);"
make the compiler satisfied??
best regards
Stefan