I HAVE a problem in repeating the task inside the loop

#include <SoftwareSerial.h>
#define SOP '<'
#define EOP '>'
SoftwareSerial RFID(10,11);

bool started = false;
bool ended = false;

char inData[80];
byte index;



  
 


char Rx_data[50];
unsigned char Rx_index = 0;
int i = 0;
char msg[160];
int sig;
char c;

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

void loop() {
  if (RFID.available()){
     c=RFID.read();
    Serial1.write(c); //it will echo the rfid code
     // Read all serial data available, as fast as possible
  while(Serial1.available() > 0)
  {//Serial1.write(c);
    char inChar = Serial1.read();
    if(inChar == SOP)
    {
       index = 0;
       inData[index] = '\0';
       started = true;
       ended = false;
    }
    else if(inChar == EOP)
    {
       ended = true;
       break;
    }
    else
    {
      if(index < 79)
      {
        inData[index] = inChar;
        index++;
        inData[index] = '\0';
      }
    }
  }
   

  // We are here either because all pending serial
  // data has been read OR because an end of
  // packet marker arrived. Which is it?
  if(started && ended)
  {
    // The end of packet marker arrived. Process the packet
    // The end of packet marker arrived. Process the packet
    char *num = strtok(inData, ",");
    if(num)
    {
       char *mesg = strtok(NULL, ",");
       if(mesg)
       {
         initGSM(); //send a mesage depending to the receive msg and cp number
  send_msg(num, mesg);
        

       }
    } 
   
    // Reset for the next packet
    started = false;
    ended = false;
    index = 0;
    inData[index] = '\0';
  }
  
    
     
    
  }
}
void send_msg(char *number, char *msg)
{
  char at_cmgs_cmd[30] = {'\0'};
  char msg1[160] = {'\0'};
  char ctl_z = 0x1A;

  sprintf(msg1, "%s%c", msg, ctl_z);
  sprintf(at_cmgs_cmd, "AT+CMGS=\"%s\"\r\n",number);
  
  sendGSM(at_cmgs_cmd);
  delay(100);
  delay(100);
  delay(100);
  sendGSM(msg1);
  delay(100);
}

void sendGSM(char *string){
  Serial.write(string);
  delay(90);
}

void clearString(char *strArray) {
  int j;
  for (j = 100; j > 0; j--)
    strArray[j] = 0x00;
}

void send_cmd(char *at_cmd, char clr){
  char *stat = '\0';
  while(!stat){
    sendGSM(at_cmd);
    delay(90);
    readSerialString(Rx_data);
    
    stat = strstr(Rx_data, "OK");
  }
  if (clr){
    clearString(Rx_data);
    delay(200);
    stat = '\0';
  }
}

void initGSM(){
  
  send_cmd("AT\r\n",1);						
//  send_cmd("ATE0\r\n",1); // Turn off automatic echo of the GSM Module	
	
  send_cmd("AT+CMGF=1\r\n",1);			// Set message format to text mode
  //Sucess
  
  Serial.println("Success");
	
  delay(1000);
  delay(1000);
  delay(1000);
}

void readSerialString (char *strArray) {
  
  if(!Serial.available()) {
    return;
  }
  
  while(Serial.available()) {
    strArray[i] = Serial.read();
    i++;
  }
}

the problem is,in the first tym it operate normally…but in a second tym did’nt…you need to reupload the program before it function correctly…please help me to solve this prob…tnx

Why is the code

for reading from the serial

port mixed in with the code

for reading from the RFID reader?

Is your enter key sticking?

Code fragments ...

char Rx_data[50];

void send_cmd(char* at_cmd, char clr)
{
    ...
    
    clearString(Rx_data);

    ...

So far, so wierd ...

'Rx_data' is a global so why even pass it to 'clearString'?

Oh and speaking of 'clearString' ...

void clearString(char* strArray)
{
    for ( int j = 100; j > 0; j-- )
    {
        strArray[j] = 0x00;
    }
}

It makes the assumption that the passed in 'strArray' is at least 99 elements long, not 100 but 99.

Assuming the size of 'Rx_data' is corrected to handle this length a better version of 'clearString' might be -

void clearString(char* strArray)
{
    for ( int j = 100; j--; )
    {
        strArray[j] = '\0';
    }
}

or given how 'C' string are zero terminated simply -

void clearString(char* strArray)
{
    strArray[0] = '\0';
}

In which case why even have a function 'clearString'

So the answer is you've written off the end of the array 'Rx_data' over who knows what so almost anything could happen thru the subsequent paths thru the 'loop'.

Don't even get me started on the global variable 'i' as used in -

void readSerialString(char* strArray)
{
    if ( !Serial.available())
    {
        return;
    }

    while ( Serial.available())
    {
        strArray[i] = Serial.read();
        i++;
    }
}

what i need to do to continously read the code?

Capital letters and proper spelling are good things.

What do you mean by this question? What "code" are you trying to continuously read?