Read data from SMS header

Hy Everyone!
I’m with some trouble acquiring data from a received SMS header.
I want to extract data like the Number and the message from a received SMS.
I don’t know why the counters are not working correctly and why the password check always returns false.

All the help is welcome!

char ReceivedSMS[120] = ""; 
int RcvdCheck = 0; 
int RcvdConf = 0;
int indice = 0;
int RcvdFim = 0;
char number[13]; 

int MsgLength = 0; 
String strNumber = ""; 

char password[5] = "1234"; 


char extractedNumber[13];
char receivedTxt[25];


//######################################
//          Functions
//######################################

void Response()
{
  int count = 0;

  while (1)
  {
    if (Serial1.available())
    {
      char data = Serial1.read();
      if (data == 'K') {
        Serial.println("OK");
        break;
      }
      if (data == 'R') {
        Serial.println("ERROR");
        break;
      }
    }
    count++;
    delay(10);
    if (count == 1000) {
      Serial.println("GSM OFFLINE");
      break;
    }
  }
}

void Config()
{
  Serial.println("START: ");
  Serial.println();

  delay(1000);
  Serial.print("Feedback Disable:           ");
  Serial1.print("ATE0\r"); 
  Response();

  Serial.print("GSM STATUS:                ");
  Serial1.print("AT\r"); 
  Response();

  Serial.print("SMS MODE:        ");
  Serial1.print("AT+CMGF=1\r"); 
  Response();

  Serial.print("SMS AS TEXT:    ");
  Serial1.print("AT+CNMI=1,2,0,0,0\r"); 
  Response();

  Serial.print("CLEAN SMS MEMORY:        ");
  Serial1.println("AT+CMGD=1,4\r"); 
  Response();

}

void ClearBuffers()
{
  strcpy(ReceivedSMS, "");
  strcpy(receivedTxt, "");
  RcvdCheck = 0;
  RcvdConf = 0;
  indice = 0;
  RcvdFim = 0;
  String strNumber = "";


  for (int i = 0; i < 13; i++)
  {
    number[i] = ' ';
  };

  MsgLength = 0;
}


void extractText()
{
  int contador = 0;
  int contadorVirgula = 0;
  int contadorMais = 0;

  char pelica = '"';
  char virgula = ',';
  char mais = '+';

  int a, b = 0;


          for (int x = 0; x < 120; x++)
          {           
            
                if (contador == 1)
                {
                  extractedNumber[a] = ReceivedSMS[x];
                  a++;                
                }

                if (contador == 6)
                {
                  receivedTxt[b] = ReceivedSMS[x];
                  Serial.print(receivedTxt[b]);
                  b++;                
                }
           
 
                if (ReceivedSMS[x] == pelica)
                {
                  contador++;
                }
          }




  
  Serial.println("EXTRACTED:");
  extractedNumber[13]='\0';
  Serial.println(receivedTxt);
  Serial.println(extractedNumber);
  


  Serial.println("COUNTERS:");
  Serial.println(contador);
  Serial.println(contadorVirgula);
  Serial.println(contadorMais);
}


void RecSMS()
{


  if (Serial1.available())
  {

    char data = Serial1.read();

    if (data == '+') {
      RcvdCheck = 1;
    }
    if ((data == 'C') && (RcvdCheck == 1)) {
      RcvdCheck = 2;
    }
    if ((data == 'M') && (RcvdCheck == 2)) {
      RcvdCheck = 3;
    }
    if ((data == 'T') && (RcvdCheck == 3)) {
      RcvdCheck = 4;
    }
    if (RcvdCheck == 4) {
      RcvdConf = 1;
      RcvdCheck = 0;
    }


    if (RcvdConf == 1)
    {
      if (data == '\n') {
        RcvdFim++;
      }
      if (RcvdFim == 3) {
        RcvdFim = 0;
      }

      ReceivedSMS[indice] = data;
      indice++;

      if (RcvdFim == 2) {
        RcvdConf = 0;
        MsgLength = indice - 2;
        indice = 0;
      }

      if (RcvdConf == 0)
      {

        for (int x = 4; x < 17; x++)
        {
          number[x - 4] = ReceivedSMS[x];

        }

        strNumber = number;


        Serial.println(strNumber);

        Serial.println(ReceivedSMS);

       
        extractText();
       



        if (strstr(receivedTxt, password)!= NULL)
        {
          Serial.println("PASSWORD VALIDATED");
        }
        else
        {
          Serial.println("PASSWORD ERROR");
        }

        Serial.println("");
        Serial.println("##################################################");
        Serial.println("");


        ClearBuffers();
      }
    }
  }
}
//#####################################################

void setup()
{
  Serial.begin(9600);
  Serial1.begin(9600);
  Config();
}

void loop()
{
  RecSMS();
}
  int a, b = 0;

What value is in a after this statement? If you said zero, you'd be wrong.

                  extractedNumber[a] = ReceivedSMS[x];
                  a++;

Write at some random location, before, in the middle of, or way past the end of the array and then increment the junk in a. NOT a good idea.

Your excessive number of blank lines

and your
piss-poor indenting
leave

a lot to be desired. Tools + Auto Format can help with the indenting. Delete the

excess blank lines yourself.