Trouble with String comparison

Hi there!

I'm using Tiny Sine 3G GSM Shield (SIM5320E) and Arduino Mega 2560 along with two sensors. My aim of the project is:

To send alert SMS/s to the identified person's mobile number. For this I'm using "ABC" as password, as an example. Whenever the user sends "ABC" SMS to the GSM-Arduino Mega 2560, the code should compare the incoming SMS with the password set already in the code. If the SMS matches with the password, "SEND Alert SMS" to the sender of correct password otherwise DO NOT SEND SMS.

Independent of string comparison, I got the SEND SMS part working using the sender's caller-ID. I have written my code in such a way that, it reads all the SMS's to send alert SMS to the caller-ID number. But at the moment it is sending the SMS to the last sender's mobile number. I'm having trouble placing string comparison part in the loop function. How can I compare each message read by the GSM?--compare the SMS with the password?--if say 5th SMS matches password then send SMS only to the 5th caller-ID number rather than last sender which it is doing at the moment.

#include "Adafruit_FONA.h"

#define FONA_TX 11
#define FONA_RX 12
#define FONA_RST 9

// this is a large buffer for replies
char replybuffer[255];
#include <SoftwareSerial.h>
SoftwareSerial fonaSS = SoftwareSerial(FONA_TX, FONA_RX);
SoftwareSerial *fonaSerial = &fonaSS;

Adafruit_FONA_3G fona = Adafruit_FONA_3G(FONA_RST);

uint8_t type;

void setup() {

  while (!Serial);
  Serial.begin(9600);
  Serial.println(F("FONA basic test"));
  Serial.println(F("Initializing....(May take 3 seconds)"));

  fonaSerial->begin(4800);
  if (! fona.begin(*fonaSerial)) {
    Serial.println(F("Couldn't find FONA"));
    while (1);
  }
}
void loop()
{  
// Timer Initialization
  static unsigned long startTime = 0; 
  char password[] = "ABC";
  // read all SMS
        int8_t smsnum = fona.getNumSMS();
        uint16_t smslen;
        int8_t smsn; 
        char callerIDbuffer[32]; 
         if (fona.available()){
          if ( (type == FONA3G_A) || (type == FONA3G_E) ) {
            smsn = 0; // zero indexed
            smsnum--;
          } else {
            smsn = 1;  // 1 indexed
          }  
  
        for ( ; smsn <= smsnum; smsn++) {
          Serial.print(F("\n\rReading SMS #")); Serial.println(smsn);
          if (!fona.readSMS(smsn, replybuffer, 250, &smslen)) {  // pass in buffer and max len!
            Serial.println(F("Failed!"));
            break;
          
          }
          // if the length is zero, its a special case where the index number is higher
          // so increase the max we'll look at!
          if (strcmp(password,replybuffer)!= 0){
          if (smslen == 0) {
            Serial.println(F("[empty slot]"));
            smsnum++;
            continue;
            }
          }
          Serial.print(F("***** SMS #")); Serial.print(smsn);
          Serial.print(" ("); Serial.print(smslen); Serial.println(F(") bytes *****"));
          Serial.println(replybuffer);
          Serial.println(F("*****"));
          if (! fona.getSMSSender(smsn, callerIDbuffer, 31)) {
            Serial.println("Didn't find SMS message in slot!");
          }
          Serial.print(F("FROM: ")); Serial.println(callerIDbuffer);
            } 
    
          if (millis() - startTime > 1UL * 60UL * 1000UL) {
          //        //sendAlert();
          Serial.println("Sending reponse...");
          startTime = millis();
          fona.sendSMS(callerIDbuffer, "Hey, I got your text!");
        }
     }
}

Capture1.PNG

Maybe you have a \r or \n in the received data?