I am doing a motorcycle security system. In this system, I will receive a message from GSM in the form {password:operation (like start,stop,alarm):time}
.
Example:(9990:start:30)
now i need to split each term seperately (a=9990,b=start,c=30).help me to solve
-
1You may need to say how you receive the message or how it's stored. As is, the question is vague. Also edit the question and add an explained example, like "{14:C:123}"James Waldby - jwpat7– James Waldby - jwpat72016年02月18日 06:05:57 +00:00Commented Feb 18, 2016 at 6:05
1 Answer 1
Simplest solution is to use sscanf().
int password;
char operation;
int time;
char* buf = "{14:C:123}";
int n = sscanf(buf, "{%d:%c:%d}", &password, &operation, &time);
Serial.print(F("n="));
Serial.println(n);
Serial.print(F("password="));
Serial.println(password);
Serial.print(F("operation="));
Serial.println(operation);
Serial.print(F("time="));
Serial.println(time);
answered Feb 18, 2016 at 10:04