Apr 20, 2011 #1 MahmoudHassan Full Member level 6 Joined Oct 4, 2010 Messages 349 Helped 44 Reputation 90 Reaction score 40 Trophy points 1,328 Activity points 3,913 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
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
Apr 20, 2011 #2 H horace1 Advanced Member level 5 Joined Nov 18, 2008 Messages 2,118 Helped 596 Reputation 1,188 Reaction score 571 Trophy points 1,393 Location Norwich, UK Activity points 13,063 you can use the string tokeniser strtok() strtok - C++ Reference
Apr 20, 2011 #3 MahmoudHassan Full Member level 6 Joined Oct 4, 2010 Messages 349 Helped 44 Reputation 90 Reaction score 40 Trophy points 1,328 Activity points 3,913 but there is no Null in MikroC that can be used so how i can terminate the while statement ?
Apr 21, 2011 #4 MahmoudHassan Full Member level 6 Joined Oct 4, 2010 Messages 349 Helped 44 Reputation 90 Reaction score 40 Trophy points 1,328 Activity points 3,913 i need urgent help PLZZZ
Apr 21, 2011 #5 andre_luis Super Moderator Staff member Joined Nov 7, 2006 Messages 9,593 Helped 1,190 Reputation 2,399 Reaction score 1,207 Trophy points 1,403 Location Brazil Activity points 55,667 Why don´t you add manually that char at the end of string ?
Apr 21, 2011 #6 H horace1 Advanced Member level 5 Joined Nov 18, 2008 Messages 2,118 Helped 596 Reputation 1,188 Reaction score 571 Trophy points 1,393 Location Norwich, UK Activity points 13,063 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""
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""
Apr 21, 2011 #7 MahmoudHassan Full Member level 6 Joined Oct 4, 2010 Messages 349 Helped 44 Reputation 90 Reaction score 40 Trophy points 1,328 Activity points 3,913 @ 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
@ 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