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
What is #ifdef ? What is its application?
How can I pad a string to a known length?
When is a “switch” statement preferable over an “if” statement?
Why do we use null pointer?
Tell us bitwise shift operators?
In C programming, how do you insert quote characters (‘ and “) into the output screen?
Why is structure important for a child?
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
Can a function argument have default value?
Explain high-order bytes.
while initialization of array why we use a[][2] why not a[2][]...?
What are the properties of union in c?
How variables are declared in c?
How do I send escape sequences to control a terminal or other device?
Differentiate between a structure and a union.