Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Why this code is not working as expected ?

Status
Not open for further replies.

milan.rajik

Banned
Joined
Apr 1, 2013
Messages
2,524
Helped
540
Reputation
1,078
Reaction score
524
Trophy points
1,393
Activity points
0
Why this code is not working as expected ?

I need to extract date and time from AT+CMGR header. The function has these arguments.

*s1 = in buffer
*s2 = out buffer

It works like this. It loops unsti it finds the 7th double quotes and then after coming out of loop it increments once. Then it loops again until '+' is encountered which is 1st '+' after 7th '"'. so, p = 7 and q = 1. Also if *s1 and *s2 is loaded into watch window it doesn't show the whole array.


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
char buffer1[] = "+CMGR: \"REC UNREAD\",\"+919900516837\",\"\",\"14/12/17,23:44:27+22\"\r\n20!4#gt\r\n\r\n";
char buffer2[20];
 
void GSM_Split(char *s1, char *s2, char p, unsigned int startIndexP, char q, unsigned startIndexQ) {
 
      unsigned int a = 0, b = 0;
      
      while(a != startIndexP) {
 
             if(*s1 == p)a++;
             *s1++;
      }
      
      *s1++;
      
      while(b != startIndexQ) {
             if(*s1 == q)b++;
             *s2++ = *s1++;
      }
      
      *s2 = '\0';
}
 
GSM_Split(buffer1, buffer2, '"', 7, '+', 1);

 

hello,

i encountered some problems when using "\" caractere
in a string variable.. because interpreted as an escape sequence car
(like the use of \r or \n).
the counter measure i applied is to use the ascii code of "\" in the right place inside
the char buffer.

it was for declare a file path with sub directories..y
 
Try looping 'strtok( )' 7 times with quotes as the search character, it will return a pointer to the character after the 7th quote which is date and time you are after.
You can also do it by searching for the commas in the string using the same method.

Brian.
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top