SD card data

Hello, I have a problem. I want SD card file from Ethernet shield write on TFT display. It goes but in the end of line are always weird signs. Do you know what can I do ?

void Show(){                    //show file
   
  digitalWrite(10, HIGH);  //ether
  digitalWrite(4, LOW);  //karta
  digitalWrite(53, HIGH); //touch
  
  char inputString [100];
  char inputChar;
  int stringIndex = 0; // String stringIndexing int; 
  int i= 40;
  int g= 60;
  int p= 70;
  
  myTouch.InitTouch();
  myTouch.setPrecision(PREC_HI);
  myGLCD.InitLCD();
  myGLCD.setFont(SmallFont);
  myGLCD.clrScr();
  myGLCD.setBackColor(255,255,255);
  myGLCD.fillRect(0,0,319,239);
  myGLCD.setColor(120, 120, 255); 
  myGLCD.print("SHOW RESULTS:", CENTER, 20);
  
   
  Serial.println("Initializing SD card...");
  if (!SD.begin(4)) {
     Serial.println("initialization failed!");
     return;
  }
  
  Serial.println("initialization done.");       
  myFile = SD.open("dp.txt");
  if (myFile){
    Serial.println("dp.txt:");
    while (myFile.available()) {
      inputChar = myFile.read();
      if (inputChar != '\n'){ // define breaking char here 
         inputString[stringIndex] = inputChar; // Store it
         stringIndex++; // Increment where to write next
      }
      else{
    //Serial.print("test: "); // shows that the program is cycling, for debugging only
        myGLCD.print(inputString, 10, g);
        stringIndex = 0; // clear the value for the next cycle
        g=g+20;
      }
    }
    myFile.close();
  } 
  else {
    Serial.println("error opening test.txt");
  }

Screenshot from 2016-04-30 10:03:51.png

        inputString[stringIndex] = '\0';  ////  Terminate the string
        myGLCD.print(inputString, 10, g);

thanks it looks better but there’s still one sign >:( Look in attachment please

Screenshot from 2016-04-30 14:44:01.png

Maybe the lines in the SD file have carriage return/line feed at the end ('\r','\n'). You end the read with '\n', that leaves the '\r' behind, at the end.

So when I use \r instead of \n some some special sign is now on the start of the line. when i use \r \n nothing happened.

Screenshot from 2016-04-30 15:37:12.png

OK try this,

inputString[stringIndex - 1] = '\0';  ////  Terminate the string and over write the '\r'

make this line (leave as original)

if (inputChar != '\n'){ // define breaking char here

That will overwrite the '\r' with the terminating null. If this does not work, then I am wrong about the 'r'. It was a guess anyway cause I can't see what is on the card or where the data comes from.

its great, thank you so much :slight_smile: