C code help, I'm trying to analyzed text

Status
Not open for further replies.

Kfir Maymon

Member level 1
Joined
Sep 20, 2013
Messages
40
Helped
1
Reputation
2
Reaction score
1
Trophy points
8
Location
Israel
Visit site
Activity points
315
Hi , I have sim900 GPRS connect to pic 16f628a
I'm trying to operate an ac with SMS,
My problem is that I want him to work only if my phone send the SMS.

If some one have a sample code it will be great.

I'm reading this line from my sim900

+cmgr: "REC UNREAD","+972542230352","","14/06/27,16:40:05+12"
SMS text in hear


How can compare the phone number and the contact of the SMS?
 

extract the phone number from the string then compare it with the one you are looking for

e.g.
Code:
    char data[]="+cmgr: \"REC UNREAD\",\"+972542230352\",\"\",\"14/06/27,16:40:05+12\" ";
    char phone[50]={0};
    strcpy(phone, strstr(data,"\"+")+2);
    *strstr(phone,"\"") = 0;
copy the string starting with "+ then replace the " with 0 to terminate the string
 
Alternatively look at the "strtok()" function which will split a string into parts depending on the delimiter between them. It has the advantage of working whatever the string contents are rather than chopping it at a particular place form the beginning. If you use a comma as the delimiter it will return:
string 1 = "+cmgr: "REC UNREAD",
string 2 = "+972542230352"
string 3 = "14/06/27
string 4 = 16:40:05+12"

You can then compare string 2 with your expected number to see if they match.

Brian.
 
Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…