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

Explain what is the best way to comment out a section of code that contains comments?

939


What is the meaning of && in c?

770


What header files do I need in order to define the standard library functions I use?

773


What is non linear data structure in c?

795


Can main () be called recursively?

894


What is the most efficient way to store flag values?

921


When is the “void” keyword used in a function?

1167


How will you find a duplicate number in a array without negating the nos ?

1875


What is header file in c?

847


What is a pointer and how it is initialized?

838


What are two dimensional arrays alternatively called as?

959


Write a code of a general series where the next element is the sum of last k terms.

826


Explain the advantages and disadvantages of macros.

859


what are non standard function in c

1669


Is struct oop?

792