i am using gsm modem ! I USE CMGL COMMAND TO DISPLAY THE
LIST OF MESSAGES ! I WANT TO READ EACH MESSAGE ONE BY ONE
AND GET EACH MESSAGE INDEX USING C PROGRAM ! THE RESPONSE OF
THE MODULE AFTER AT+CMGL IS
---CMGL: 1,"REC
READ","+85291234567",,"07/05/01,08:00:15+32",145,37
It is easy to list SMS text messages.----
I WANT THE PROGRAM TO GET THE NUMBER "37"{MESSAGE LENGTH}
AS WELL AS "1"(MESSAGE INDEX NUMBER"
PLEASE HELP

Answer Posted / senthil

assume the read message string is stored in a buffer buf already

char buf[100] = "CMGL: 1,\"REC READ\",\"+85291234567\",,\"07/05/01,08:00:15+32\",145,37";
int comma_cnt = 0, i, j;
char msgidx[10];
char msglen[10];

if(strncmp("CMGL:", buf, 5) == 0)
{
// copy message index till comma
for(i=5, j=0; buf[i] != ','; i++)
{
msgidx[j++] = buf[i];
}
msgidx[j] = 0;

i++; // loc after comma;
comma_cnt = 1;

for(; buf[i] != 0; i++)
{
// check for commas
if(buf[i] == ',')
{
// check for 7th comma
if(++comma_cnt == 7)
{
comma_cnt = 0;
strcpy(msglen, buf+i+1);
printf("message index = %s\n", msgidx);
printf("message length = %s\n", msglen);
}
}
}
}

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is #ifdef ? What is its application?

640


How can I pad a string to a known length?

608


When is a “switch” statement preferable over an “if” statement?

639


Why do we use null pointer?

601


Tell us bitwise shift operators?

592






In C programming, how do you insert quote characters (‘ and “) into the output screen?

887


Why is structure important for a child?

601


write a program which the o/p should b in such a way that s triangle if I/p is 3,a Square/rectangle if I/P=4,a pentagon if I/P=5 and so on...forget about the I/P which is less than 3

1639


Can a function argument have default value?

666


Explain high-order bytes.

670


while initialization of array why we use a[][2] why not a[2][]...?

1859


What are the properties of union in c?

582


How variables are declared in c?

567


How do I send escape sequences to control a terminal or other device?

604


Differentiate between a structure and a union.

756