Need help with GSM to send feedback SMS [SOLVED]

Hello, I'm doing a project using Arduino Uno and Siemens TC35 GSM Development Board. I want to be able to send an SMS to the system to check the status of a certain component in the project, and then have the Arduino send a reply SMS back to the number who have sent the status-check SMS. Right now I am having a problem retrieving the sender's number and would appreciate any help I can get with part of the code below.

void checkSMS()
{
  //method to check each char
  inchar = gsmSerial.read();
  if (inchar == 'C')
  {
    delay(10);
    inchar = gsmSerial.read();
    if (inchar == 'H')
    {
      delay(10);
      inchar = gsmSerial.read();
      if (inchar == 'E')
      {
        delay(10);
        inchar = gsmSerial.read();
        if (inchar == 'C')
        {
          delay(10);
          inchar = gsmSerial.read();
          if (inchar == 'K')
          {
            delay(10);
            sendContent = "";
            sendContent += "Checking";
            sendSMS(getSenderID());

          }
        }
      }
    }
  }
  else
  {
    sendContent = "";
    sendContent += "Invalid command";
    sendSMS(getSenderID());

  }
}

char *getSenderID()
{
  gsmSerial.println("AT+CMGR=1");
  int n = 0;
  while(gsmSerial.available())
  {
    smsContent[n] = gsmSerial.read();
    n++;
  }
  smsSenderPos = strstr(smsContent, ",");
  smsSenderPos += 2;

  int m = 0;
  while (smsSenderPos[m] != '"')
  {
    smsSender[m] = smsSenderPos[m];
    m++;
  }
  return smsSender;
}

A regular response for "AT+CMGR=1" is: +CMGR: "REC READ","+60172xxxxxx",,"13/05/23,16:24:28+32" CHECK

OK

Right now I'm trying to get the sender's number by detecting the comma and retrieving the data in between the ' " '. Anybody can help with me with the code? (Also for the first function, if you have an easier method than to check each character of the sms received, it would be great too. :sweat_smile:)

[SOLVED]

Reading a letter, waiting a little while, hoping another letter arrives, reading a letter, waiting a little while, hoping another letter arrives, etc., as you are doing in checkSMS(), is a really bad design.

The message includes some kind of end-of packet marker. You need to figure out what that is, and read (and store) whatever data has arrived, as fast as possible, using the data only when the end of packet marker has arrived.

In getSenderID(), you assume that a complete message has arrived and is ready to read. Not a reasonable assumption. Try again.