Split string for microcontroller

Status
Not open for further replies.

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
 

but there is no Null in MikroC that can be used
so how i can terminate the while statement ?
 

Why don´t you add manually that char at the end of string ?
 

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""
 
@ 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.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…