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.

How to get a part of string from another string using pointer?

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
I have two string pointers.


Code C - [expand]
1
2
unsigned char *buff2 = "Your Google verification code is 484537"
unsigned char *buff1 = "                                                                                                   ";



I need to move the string "verification code" from buff2 to buff1. How to do that?


Edit:


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
unsigned char gsmData[] = "AT+CMGR=156\r\r\n+CMGR: \"REC READ\",\"p4w4w274\",,\"2013/01/02 19:16:19+22\"\r\nYour Google \r\nverification code is 484537;\r\n"
unsigned char temp[160];
 
void GSM_GPRS_Split(char *buff1, char *buff2, char delimit1, unsigned int delimit1Count, char delimit2, unsigned int delimit2Count){
                       
        unsigned int delimit1Cnt = 0, delimit2Cnt = 0;
        
        while(delimit1Cnt != delimit1Count){    
                  if(*buff2 == delimit1)delimit1Cnt++;
                  *buff2++;
        }
        
        while(delimit2Cnt != delimit2Count){
                  if(*buff2 == delimit2)delimit2Cnt++;
                  *buff1++ = *buff2++;
        }
                
        *buff1--;
        *buff1 = '\0';
        
}



//Usage

GSM_GPRS_Split(&temp, &gsmData, '\n', 2, '\r', 2);


Will this code work?

I need to copy data which appears between 2nd '\n' and '\r' which appears at the end of message.

*buff2 increments till 2nd '\n' is found then it starts copying data to *buff1 till it encounters 2nd '\r' from the beginning of message.

Is my code correct?
 
Last edited:

Made a library for mikroC PRO PIC for PIC18Fs. It searches for ith occurence of delimiter 1 and then extracts the data from this index to jth occurence of delimiter 2. In the below code the text after 2nd '\n' ("Your...) till 2nd occurence of '\r' from this position which is "...484537;" is extracted.

So, sub string "Your Google \r\nverification code is 484537;" is extracted.

Example usage:


Code C - [expand]
1
2
3
4
5
6
7
8
unsigned char testData[] = "AT+CMGR=156\r\r\n+CMGR: \"REC READ\",\"p4w4w274\",,\"2013/01/02 19:16:19+22\"\r\nYour Google \r\nverification code is 484537;\r\n";
unsigned char temp[160];
 
void main(){
 
           GSM_GPRS_Split(&temp, &testData, '\n', 2, '\r', 2);
 
}




Edit: Updated file attached. Place the .mlk file in \mikroC PRO PIC\Defs folder and .mcl file in \mikroC PRO PIC\Uses\P18 folder
 

Attachments

  • __Lib_GSM_GPRS.rar
    1.2 KB · Views: 35
  • GPS_GSM.rar
    5.3 KB · Views: 40
Last edited:

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top