Help with gsm code..Can't figure out why this is happening

I found this gsm code which I found on the forum, it works but not as it supposed to. The code supposed to show caller’s number and message seperately.

#include <SoftwareSerial.h>
SoftwareSerial GoMySerial(2, 3);

char RcvdMsg[200] = "";
int RcvdCheck = 0;
int RcvdConf = 0;
int index = 0;
int RcvdEnd = 0;
char MsgMob[15];
char MsgTxt[50];
int MsgLength = 0;
String number;
char inchar;
char outString[22];
int v = 42;
void setup()
{
  Serial.begin(9600);
  GoMySerial.begin(9600);

  GoMySerial.write("ATE0\r");
  Serial.println("Echo enabled");
  delay(2500);
  GoMySerial.write("AT\r");
  Serial.println("Echo enabled");
  delay(2500);
  GoMySerial.write("AT+CMGF=1\r");
  Serial.println("Echo enabled");
  delay(2500);
  GoMySerial.write("AT+CSCS=\"GSM\"\r");
  Serial.println("Echo enabled");
  delay(2500);
  GoMySerial.write("AT+CNMI=1,2,0,0,0\r");
  Serial.println("Echo enabled");
  delay(2500);
  GoMySerial.write("AT+CMGD=1,4\r");
  Serial.println("Echo enabled");
  delay(2500);
}

void loop()
{
  recSms();
}

void recSms()
{
  if (GoMySerial.available())
  {
    char data = GoMySerial.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')
      {
        RcvdEnd++;
      }
      if (RcvdEnd == 3)
      {
        RcvdEnd = 0;
      }
      RcvdMsg[index] = data;
      index++;

      if (RcvdEnd == 2)
      {
        RcvdConf = 0;
        MsgLength = index - 2;
        index = 0;
      }
      if (RcvdConf == 0)
      {
        Serial.print("Mobile Number is: ");
        for (int x = 4; x < 18; x++)
        {
          number += RcvdMsg[x];
          MsgMob[x - 4] = RcvdMsg[x];
        }
        Serial.print(number);
        Serial.println();
        Serial.print("Message Text: ");
        for (int x = v; x < MsgLength; x++)
        {
          MsgTxt[x - v] = RcvdMsg[x];
          inchar = MsgTxt[x - v];
        }
        Serial.print(inchar);
        Serial.println();
        GoMySerial.print("AT+CMGD=1,4\r");
        RcvdCheck = 0;
        RcvdConf = 0;
        index = 0;
        RcvdEnd   = 0;
        MsgMob[15];
        MsgTxt[50];
        MsgLength = 0;

        Serial.flush();
        GoMySerial.flush();

        /* if (inchar == '#')
          {
           sendInfo();
          }*/

      }
    }
  }
}

and this is the result when I send a text message

Mobile Number is: +2347056643757
Message Text: m

it shows my number but just a letter from the message, and this happened when i send another text message

Mobile Number is: +2347056643757+2347056643757
Message Text: m

it shows my number twice and still a letter from my message.

you are outputting inchar OUTSIDE the iterator.

for (int x = v; x < MsgLength; x++)
        {
          MsgTxt[x - v] = RcvdMsg[x];
          inchar = MsgTxt[x - v];
        
        [color=red]Serial.print(inchar);[/color]
}

Thanks it worked for the message but I still get more than one phone number when I send message more than ounce

Mobile Number is: +2347056643757+2347056643757
          number += RcvdMsg[x];

You don't reset number to a null string after you've used it, so you'll keep appending numbers to it.

Why do you use String for number when you've used null-terminated C strings for everything else? Use a null-terminated string for number as well.

       MsgMob[15];
        MsgTxt[50];

What are these two declarations supposed to do here?

Pete

On the whole I think it is better to poll for SMS messages rather than assume that they will be output as unsolicited messages. Different modules do things differently but all of them react to polling.