SD card problem

When the GPS receive latitude and longitude information,
LCD display normal values??,
but to write to the SD card,
and then use the PC to read it,
sometimes it will show full data,
but it almost show me garbled characters.

#include <SD.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <TinyGPS.h>  // Add to library folder
#include <string.h>
#include <SoftwareSerial.h>

File myFile;
LiquidCrystal_I2C lcd(0x27, 16, 2);
double d1,d2,gain,kp=0.1;
float flat, flon, x,y,lat2,long2,d3,d4,d5,d6,d7,a3,a4,a5,a6,a7,c,a1,b1;
char *pEnd;
TinyGPS gps;
SoftwareSerial nss(8, 255);// Yellow wire to pin 6
SoftwareSerial nano(4,3);
char value[20];
int i;
void setup() 
{
  Serial.begin(9600);
  nano.begin(9600);
  nss.begin(4800);
  if (!SD.begin(10)) 
  {
    return;
  }
  lcd.init();
  lcd.backlight();
  lcd.setCursor(0,0);
  lcd.print("Waiting Target");
  delay(1000);
wait:
  if(Serial.available()>0)
  {
    for(i=0;i<20;i++)
    {
    value[i] = Serial.read();
    }
    lcd.clear();
    Serial.println(value);
    char *pEnd;
    d1=strtod(value,&pEnd);
    d2=strtod(pEnd,NULL);
    lcd.setCursor(0,0);
    lcd.print(d1, 6);
    lcd.setCursor(0,1);
    lcd.print(d2, 6);
    goto wait2;
  }
  else
  {
  //Serial.println('1');
  goto wait;
  }
wait2:delay(500);
}
void loop()
{
 lcd.clear();
 //lcd.print("Reading GPS");
//  Serial.println("Reading GPS");
  bool newdata = false;
  unsigned long start = millis();
  while (millis() - start < 1000) 
  {  
    if (feedgps())
      newdata = true;
  }
  if (newdata) {
    gpsdump(gps);  }
}
// Get and process GPS data
 void gpsdump(TinyGPS &gps){
  unsigned long age;
  gps.f_get_position(&flat, &flon, &age);
  x=flat,y=flon;
  Serial.print(x, 6); Serial.print(", "); 
  Serial.println(y, 6);
  lcd.setCursor(0,0);
  lcd.print(x, 6);
  lcd.setCursor(0,1);
  lcd.print(y, 6);
  float course_to (float x, float y, float d1, float d2,float a1,float b1);
  {
    if ((d2-y)<0)
    {
d3=(24-x)*111.11111*1000;
d4=(sqrt(sq(d1-x)+sq(d2-y)))*111.11111*1000;
  d5=(sqrt(sq(d2-y)+sq(d1-24)))*111.11111*1000;
  d6=((sq(d3)+sq(d4)-sq(d5))/(2*d3*d4));
  d7=((acos(d6))*57.29578)*(-1);
    }
    else
    {
    d3=(24-x)*111.11111*1000;
d4=(sqrt(sq(d1-x)+sq(d2-y)))*111.11111*1000;
  d5=(sqrt(sq(d2-y)+sq(d1-24)))*111.11111*1000;
  d6=((sq(d3)+sq(d4)-sq(d5))/(2*d3*d4));
  d7=((acos(d6))*57.29578);
}
    if((y-b1)<0)
    {
  a3=(24-a1)*111.11111*1000;
  a4=(sqrt(sq(x-a1)+sq(y-b1)))*111.11111*1000;
  a5=(sqrt(sq(y-b1)+sq(x-24)))*111.11111*1000;
  a6=((sq(a3)+sq(a4)-sq(a5))/(2*a3*a4));
  a7=((acos(a6))*57.29578)*(-1);
    }
  else if((y-b1)>0)
  {
      a3=(24-a1)*111.11111*1000;
  a4=(sqrt(sq(x-a1)+sq(y-b1)))*111.11111*1000;
  a5=(sqrt(sq(y-b1)+sq(x-24)))*111.11111*1000;
  a6=((sq(a3)+sq(a4)-sq(a5))/(2*a3*a4));
  a7=((acos(a6))*57.29578);
  }
  else 
  {
    a7=0;
  }
  c=a7-d7;
/*  Serial.print(a1,5); Serial.print(", ");
  Serial.println(b1,5);
  Serial.print("Heading : ");
  Serial.println(a7,5);
  Serial.print("C-T angle : ");
  Serial.println(d7,5); //cat to target angle
  Serial.print("H-T : ");
  Serial.println(c,5);  //delta angle,H-T
  Serial.print("C-T distance : ");
  Serial.println(d4,2); //car to target distance
*/  a1=flat,b1=flon;
  myFile=SD.open("gps.txt",FILE_WRITE);
  if(myFile)
  {
    myFile.print(x,6);
    myFile.print(',');
    myFile.println(y,6);
    delay(50);
  }
  
  if(d4<5)
  {

    nano.write('0');
    goto done;
  }
  if(c<0)
  {
    c += 380;
    Serial.println(c);
    nano.write(c);
  }
  else if(c>0)
  {
    Serial.println(c);
    nano.write(c); 
  }
  else
  {
    gain=c*kp;
    nano.write(gain);
    delay(100);
  }
done:delay(100);
}
}


// Feed data as it becomes available 
bool feedgps(){
  while (nss.available()) {
    if (gps.encode(nss.read()))
      return true;
  }
  return false;
}
  if(Serial.available()>0)
  {
    for(i=0;i<20;i++)
    {
    value[i] = Serial.read();
    }
    lcd.clear();
    Serial.println(value);

If there is at least one character to read, read all 20 of them.

Don't bother NULL terminating the array.

Pass it to a function that expects a NULL terminated array.

Sorry. In the space of 8 lines, that's three fails. I don't read past 3 fails.