1

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

asked Feb 18, 2016 at 4:36
1
  • 1
    You 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}" Commented Feb 18, 2016 at 6:05

1 Answer 1

3

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

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.