reading serial input

I'm trying to read the number from an incoming call, and then store the number, wait for a trigger and then sms that number, the idea is that if I get a new mobile phone, all I do to reset the number that the alarm unit sends the message to is call it and then hangup.

If I call the unit I get the following on the serial monitor:

+CLIP: "My phone number",129

RING

+CLIP: "My phone number",129

NO CARRIER

+SIND: 6,1

I can send an sms by using this code:

Serial.println("AT+CMGF=1");
  Serial.println("AT+CMGS=\"My phone number\"");
  Serial.print("Baymonitor 1 Finished");
  Serial.write(26);

I just can not work out how to get the "my phone number" from the serial input into my program and then back out when its required.

A gentle kick in the right direction would be hugely appreciated. I hope some one can make sense of my ramblings..

OK there may be a better way to do this, but I’d look up the c++ references for “strtok”, and the related “strtok_r”

Essentially you feed it a string, and tell it what characters separate different fields within that string. It returns the first section of that string up to the first delimiter, and chops that bit (and the delimiter) off your original string

You’d set up a quotation mark as the delimiter, then feed it your string, and throw away the first result (it would have everything up to the first quotation mark). Feed it your string again, and it’ll return your phone number.

This is a really common thing to use for GPS applications, where you parse a NMEA string to get out the variables such as longitude and latitude from a single string. Here’s and excerpt from my GPS parser (pretty much copied from the diydrones code)

void altitude2_parse(void){
  char *token;        // this is the new string that will contain the chopped off bit
  const char delimiters[] = "$,";     // these are the delimiters
  token = strtok_r(altitude_buffer, delimiters, &brkb);//token contains just the header string "GPGGA"
  token = strtok_r(NULL, delimiters, &brkb);// now it contains the UTC time
  time=atoi(token);  // convert the string containing the time to a variable
  ...  //etc
}