Comparing the phone number.

Hello

I need some help by comparing the array who gets the cellphone number this one:

char senderNumber[20];

I want to compare it with an specific number in order to check if proceed to the code or discard the message.

I've tried with memcp function and to convert the array to integer and didn't work, the only thing that has worked was comparing each postion of the array like this:

    if (senderNumber[0] == 'x' && senderNumber[1] == 'x' && senderNumber[2] == 'x' && senderNumber[3] == 'x' && senderNumber[4] == 'x' && senderNumber[5] == 'x' && senderNumber[6] == 'x' && senderNumber[7] == 'x && senderNumber[8] == 'x' && senderNumber[9] == 'x')

Where the x is each number of my complete phone number (you don't need to know it LoL). The problem is that i need to compare more numbers and i want to know if there are other options to do it.

Thank you so much.

strcmp()?

http://www.cplusplus.com/reference/cstring/strcmp/

dannable:
strcmp()?

I did this:

char senderNumber[10];
char number[] = "XXXXXXXXXX";

 if (sms.available())
  { 
sms.remoteNumber(senderNumber, 10);
    if (strcmp (senderNumber,number) == 0)
{code}
}

And program didn't work, it starts but does nothing, like if the void part doesn't exist. My message was never read.

There was no mention of using libraries in your original post, and your example suggested you were using character arrays.

You need to establish what type the return value is and compare accordingly. If it's a String then you can use the standard comparison operators. If a null terminated character array then strcmp() will work.

I'm using the ReceiveSMS example from Arduino the library used is #include <GSM.h> and nothing else. You said

dannable:
You need to establish what type the return value is and compare accordingly.

I think that you are talking of

sms.remoteNumber(senderNumber, 10);

How can I know that? Sorry if I'm wrong is being hard for me to understand.

You need to start looking at the documentation for the library, and if that fails find the function within the library itself. Print out the value to serial monitor to make sure that you are comparing what you expect to be?

This is why I don't often use libraries! :wink:

Oh ok. I think that I will just give up. I can't work without the library and this Shield or code, now I don't know, works when he wants, I tried differents options and then the program stopped to work, even if I use my original code now is no longer working, and sometimes I need compile and upload the code twice to see the changes.

I don't have enough knowledge to check the library, so now I'm going to start again from the beginning.
Thank you so much. :slight_smile: