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

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}" 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);

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.