Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic 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.

Register Log in

Split string for microcontroller

Status
Not open for further replies.

MahmoudHassan

Full Member level 6
Joined
Oct 4, 2010
Messages
345
Helped
43
Reputation
88
Reaction score
39
Trophy points
1,328
Activity points
3,801
hi
i have string like that
char x[] ="+CMGR: ""REC RED"",""+20120782626"",""2"",""11/03/28,17:26:33+00""";

mobile message
and i want to split it to get
"+20120782626"

how can i do that ?
iam using
pic18f4520
and
mickroC
Thanks
 

MahmoudHassan

Full Member level 6
Joined
Oct 4, 2010
Messages
345
Helped
43
Reputation
88
Reaction score
39
Trophy points
1,328
Activity points
3,801
but there is no Null in MikroC that can be used
so how i can terminate the while statement ?
 

andre_teprom

Super Moderator
Staff member
Joined
Nov 7, 2006
Messages
9,187
Helped
1,141
Reputation
2,301
Reaction score
1,116
Trophy points
1,403
Location
Brazil
Activity points
53,394
Why don´t you add manually that char at the end of string ?
 

horace1

Advanced Member level 5
Joined
Nov 18, 2008
Messages
2,123
Helped
596
Reputation
1,188
Reaction score
573
Trophy points
1,393
Location
Norwich, UK
Activity points
13,071
this compiles OK using mcc18
Code:
      char line[100]="+CMGR: \"\"REC RED\"\",\"\"+20120782626\"\",\"\"2\"\",\"\"11/03/28,17:26:33+00""";
      char *tok = strtok(line, ",");     /* find first token */
      tok = strtok(NULL, ",");           /* get first number */
      printf("%s\n", tok);
when run it displays
Code:
""+20120782626""
 

MahmoudHassan

Full Member level 6
Joined
Oct 4, 2010
Messages
345
Helped
43
Reputation
88
Reaction score
39
Trophy points
1,328
Activity points
3,801
@ andre_teprom

this a format for message received by GSM modem the sender number is changed and i waant to get number

@horace1
it doesn't work for MikroC
But i got the idea and it works

my code in MikroC

char ee[20];
void process2(char v[])
{
strcpy(ee, strtok(v, ","));
strcpy(ee, strtok(0, ","));

}



void main()
{

Process2("+CMGR: ""REC RED"",""+20120782626"",""2"",""11/03/28,17:26:33+00""");


}













Thanks horace1 very helpful
 

Status
Not open for further replies.
Toggle Sidebar

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top