GSM GPS not getting data together

/dev:
You haven't tried a single suggestion.

I have tried all suggestions (which ever I understood) and has implemented as well.

/dev:
You don't show your code when you ask a question.

The code was same only....the serial data on gsm is not getting flushed after each call....it is as simple as that

/dev:
You ask for code, then don't try it.

I wanted help on my code and not someone else already written code. I appreciate that but that way I wont learn anything and so I didn't used that. Sorry but thats what I believe.

/dev:
Why are you here?

To learn

And talking about the code.....have a look at this

#include <SoftwareSerial.h>
#include <TinyGPS++.h>
#include <SD.h>
#include <SPI.h>

TinyGPSPlus gps;
SoftwareSerial ss(6, 7); //gps works on it

//gsm on serial 0,1

File myFile;
String buffer[10];
boolean SDfound,flag=0,flag1,buttonPressed;

byte i = 0,n,p = 1,old_min,old_hour,old_min_track,in,buttonPin = 3;
double old_dist_lon,old_dist_lat;
String sta,s,num=""; //number goes here
char la_t[10];
char lon_g[10];

void setup() {

  Serial.begin(9600);
  delay(100);
  ss.begin(9600);
  pinMode(buttonPin, INPUT);
  Serial.println("ATE0");
  if (SDfound == 0) {
    if (!SD.begin(4)) {
      Serial.println(F("The SD card cannot be found"));
      while(1);
    }
  }
  SDfound = 1;
  
  myFile = SD.open("Welcome.txt");
  if (!myFile) {
    Serial.println(F("The text file cannot be opened"));
    while(1);
  }

  while (myFile.available()) {
    buffer[i++] = myFile.readStringUntil('\n'); 
    delay(50);
  }
  buffer[i++]=num;

  myFile.close();

}

void loop(){
  
  if(Serial.available()>0)
    sta=Serial.readString();
  
  s=sta.substring(21,31);
  if(s.length()==10){
      Serial.println("ATH\r\n");
      for(n=0;n<i;n++){
        if(s.equals(buffer[n])){
          flag=1;
          break;
        }
      }
      if(flag==1){
        in=0;
        flag=0;
      }
      else
        in=1;
      Serial.println(in);
      send_sms(n,in);
      delay(2000);    
  }
  if(buttonPressed==LOW)
    buttonPressed = digitalRead(buttonPin);
  while(ss.available()>0)
    if(gps.encode(ss.read()))
      displayInfo();  

}  

void displayInfo(){ 
  
  collect();
    
  if (gps.time.isValid() && p==1){
    p=0;
    old_hour=gps.time.hour();
    old_min=gps.time.minute();
    old_min_track=gps.time.minute();
    old_dist_lat=gps.location.lat();
    old_dist_lon=gps.location.lng();
  }

  if(gps.time.isValid()){
    if(gps.speed.mps()>11 && !buttonPressed && (gps.time.minute()-old_min>=1 || gps.time.minute()-old_min<=-1))
      send_sms(i,3); 
    if(buttonPressed){
      //Serial.println(gps.speed.mps());
      //Serial.println(gps.time.minute());
      //Serial.println(old_min_track);
      if(gps.time.minute()-old_min_track>=1 || gps.time.minute()-old_min_track<=-1){
        if(gps.location.lat()-old_dist_lat>0.001 || gps.location.lng()-old_dist_lon>0.001){
          flag1=0;
          //Serial.println("ABC");
        }
        else{
          old_dist_lat=gps.location.lat();
          old_dist_lon=gps.location.lng();
          flag1=1;
        }
      }
      if(flag1==1){
        buttonPressed=LOW;
        //Serial.println("FLAG1 LOW");
      }
    }
    if(gps.time.minute()-old_min>=1 || gps.time.minute()-old_min<=-1){
      input();        
      old_min=gps.time.minute();
    }
    if(gps.time.hour()-old_hour>=1 || gps.time.hour()-old_hour<=-1){
      input();
      old_hour=gps.time.hour();
    }
  }
}

void input() {
    myFile = SD.open("Data_log.txt",FILE_WRITE);
    if (!myFile) {
      Serial.print(F("The text file cannot be opened"));
      while(1);
    }
    else {
      collect();
      myFile.println(F("Location: Latitude = "));
      myFile.print(la_t);
      myFile.print(F(", Longitude = "));
      myFile.print(lon_g);
      myFile.print("\n");
      myFile.print(F("Time: "));
      myFile.print(gps.time.hour());
      myFile.print(":");
      myFile.print(gps.time.minute());
      myFile.print(F(" Date: "));
      myFile.print(gps.date.day());
      myFile.print("/");
      myFile.print(gps.date.month());
      myFile.print("/");
      myFile.print(gps.date.year());
      Serial.println(F("Added"));
      delay(150);
    }
    myFile.close();
}

void collect() {
  if (gps.location.isValid() && gps.date.isValid() && gps.time.isValid()){
    dtostrf(gps.location.lat(),9,6,la_t);
    dtostrf(gps.location.lng(),9,6,lon_g);
  }
}

void send_sms(byte x,byte y){
  if(gps.location.isValid()){
    delay(200);
    if(y==0){  
      /*String msg="AT+CMGS=\"+91"+ buffer[x] +"\"\r";  
      Serial.println("AT+CMGF=1");
      delay(200);
      Serial.println(msg);  */
      delay(200);
      Serial.println("Vehicle Tracked. Location: " + String(la_t) + "," + String(lon_g));
    }
    if(y==1){
      /*String msg="AT+CMGS=\"+91"+ buffer[x] +"\"\r";
      Serial.println("AT+CMGF=1");
      delay(200);
      Serial.println(msg); */ 
      delay(200);
      Serial.println("Number " + s + " tried to access Location: " + String(la_t) + "," + String(lon_g));
    }
    if(y==2){
      for(n=0;n<i;n++){
        /*Serial.println("AT+CMGF=1");
        delay(200);
        String msg="AT+CMGS=\"+91"+ buffer[n] +"\"\r";
        Serial.println(msg);  */
        delay(200);
        Serial.println("Accident Detected. Location: " + String(la_t) + "," + String(lon_g));
        delay(200);
        Serial.write(26);
      }
    }
    if(y==3){
      /*Serial.println("AT+CMGF=1");
      delay(200);
      String msg="AT+CMGS=\"+91"+ num +"\"\r";
      Serial.println(msg);  */
      delay(200);
      Serial.println("Movement Detected. Location: " + String(la_t) + "," + String(lon_g));
    }
    delay(200); 
    Serial.write(26);
  }  
}