Go Down

Topic: SOLVED:Comparing identical Char arrays in If statement. Uno, FONA 800, Rookie (Read 65 times) previous topic - next topic

link081787

Hi,
 
I am currently working on a project with an Uno, FONA 800, and a temperature sensor. Currently the system works, where I send literally any text to the FONA and it sends me the temp. Simple... But not complex enough. So I decided today that I needed more information when I text, but K.I.S.S. when my wife texts the system, which involves the system comparing my number to the caller ID on the system. Where I have the issue is at the beginning of the If statement it says that the two numbers don't match.

Code: [Select]

char EM1[32] = "+0000000000";  //Obviously not my number
char callerIDbuffer[32];  //we'll store the SMS sender number in here

 
if(EM1 == callerIDbuffer){
   Serial.println("Number Matched!!!");
   fona.sendSMS(EM1, "Test");
 }



I've been trying for several hours to convert the buffer into char, char*, and strings to make sure the format is correct, but no luck. I've even gone as far as
Code: [Select]

   Serial.println(callerIDbuffer);
    Serial.println(EM1);


to compare the two, which appear identical, but still wont go into the if statement. I also tried getting the two numbers to print out in binary so I could compare bit by bit, but couldn't get that working either.

Any suggestion would be greatly appreciated and if its something stupid simple, please feel free to speak freely. FYI i have already RTFM


PaulS

Code: [Select]
if(EM1 == callerIDbuffer){
Unless those two arrays share the same address (not bloody likely), the comparison will never be true.

strcmp() is used to compare strings.

The art of getting good answers lies in asking good questions.

link081787

I know that I tried strcmp earlier, but its working now, and thats good enough for me.

Code: [Select]

 if(strcmp(callerIDbuffer, EM1) ==0){
              Serial.println("Numbers Matched!!!");
              fona.sendSMS(EM1, "test");
            }



Thanks

Go Up