read the text file line by line from sd card and send that line to tcp port GPRS

Hii all of you,
i am working on gprs module A6..i am able to read the first line of text file from sd card and then send it to the tcp port using gprs...my question is that after successful transmission of line to tcp port..can i set flag at the start of line line so when we access sd card we are sure that that line has been transmitted..and in next iteration we will scan for that flag if flag not found at the start of line ..starts transmitting that line through gprs...?its just tricky one..but i think it would be possible ..
any suggestions...guidance will be appreciated from experts..
thanks in advance..
i am postiing my code for getting first line from text file and send it to a gprs:
i have been doing it from long time ..need help :confused:

#include <SD.h>
#include <SPI.h>
#include <SoftwareSerial.h>
SoftwareSerial SIM900(2, 3);
File printFile;
File myFile;
String buffer;
boolean SDfound;
String readstr,readfile;
char val;

void setup() {
  Serial.begin(9600);
  SIM900.begin(9600);
  pinMode(9,OUTPUT);
  digitalWrite(9,HIGH);
  if (SDfound == 0) {
    if (!SD.begin(10)) {
      Serial.print("The SD card cannot be found");
      while(1);
    }
  }
 }

void loop() {
  SDfound = 1;
  printFile = SD.open("TEST.txt");

  if (!printFile) {
    Serial.print("The text file cannot be opened");
    while(1);
  }
   while (printFile.available()) {
   buffer = printFile.readStringUntil('\n');
     Serial.println(buffer); //Printing for debugging purpose 
     
     sendGprsData();
     break;
   }
  printFile.close();
}


void ShowSerialData()
{
  while(SIM900.available()!=0) { 
  val=char(SIM900.read());
  readstr+=val;
  if (val=='\n'){
    Serial.println(readstr);
    savesentdata();
  readstr="";
  }  
  }
}

void sendtemp(){
 delay(500);
 SIM900.println(buffer);
 delay(300);
 ShowSerialData();
 SIM900.write(0x1A);
 delay(300);
ShowSerialData();
}

void sendGprsData(){

  Serial.println("TCP Receive :");
  Serial.print("AT\\r\\n");
  SIM900.println("AT"); 
  delay(5000);
  ShowSerialData();

  Serial.print("AT+CIPMUX=0\\r\\n");
  SIM900.println("AT+CIPMUX=0");  /* Single TCP/IP connection mode */
  delay(5000);
  ShowSerialData();

  Serial.print("AT+CGATT=1\\r\\n");
  SIM900.println("AT+CGATT=1"); /* Attach to GPRS Service */
  delay(5000);
  ShowSerialData();
  
  Serial.print("AT+CREG?\\r\\n");
  SIM900.println("AT+CREG?"); /* Network registration status */
  delay(5000);
  ShowSerialData();
 
  Serial.print("AT+CGATT?\\r\\n");
  SIM900.println("AT+CGATT?");  /* Attached to or detached from GPRS service */ 
  delay(5000); 
  ShowSerialData();
 
  Serial.print("AT+CGDCONT=1,\"IP\",\"ISAFE\"\r\\n");
  SIM900.println("AT+CGDCONT=1,\"IP\",\"ISAFE\""); /* Start task and set APN */
  delay(5000);
  ShowSerialData();
  
  Serial.print("AT+CGACT=1,1\\r\\n");
  SIM900.println("AT+CGACT=1,1"); /* Bring up wireless connection with GPRS */
  delay(5000);
  ShowSerialData();

  Serial.print("AT+CIFSR\\r\\n");
  SIM900.println("AT+CIFSR"); /* Get local IP address */
  delay(5000);
  ShowSerialData();

  Serial.print("AT+CIPSTART=\"TCP\",\"122.169.113.165\",1883");
  SIM900.println("AT+CIPSTART=\"TCP\",\"122.169.113.165\",1883");  /* Start up TCP connection */
  delay(5000);
  ShowSerialData();
  delay(5000);
  Serial.print("AT+CIPSEND\\r\\n");
  SIM900.println("AT+CIPSEND"); /* Send data through TCP connection */
  delay(2000);
  ShowSerialData();  
  delay(2000);
  sendtemp();
  delay(5000);
  ShowSerialData();  
  Serial.print("AT+CIPCLOSE\\r\\n");
  SIM900.println("AT+CIPCLOSE"); /* Deactivate GPRS PDP content */
  delay(5000);
  ShowSerialData();
  Serial.print("AT+CIPSHUT\\r\\n");
  SIM900.println("AT+CIPSHUT"); /* Deactivate GPRS PDP content */
  delay(5000);
  ShowSerialData();
}
void savesentdata(){
  if (readstr=="AT+CIPSEND\r\n"){
  delay(150);
  Serial.println("Data sending Started");
  digitalWrite(9,LOW);
}
if(readstr=="OK\r\n"){ 

if(digitalRead(9)==LOW){
   Serial.println("String sent");
   
/*//write to new txt file
     myFile = SD.open("sentdata.txt", FILE_WRITE);
      if (myFile) {
         myFile.println("S"+buffer);
         myFile.close();
 }
//read whole txt file
myFile = SD.open("sentdata.txt");
  if (myFile) {
      while (myFile.available()) {
      Serial.write(myFile.read());
    }
    myFile.close();
  }*/
 
   digitalWrite(9,HIGH);
}
    
  }

}