Unwanted Characters on LCD

Hello guys,

I'm trying to read the content of a text file line by line saved like this:

ABC 123
DEF 456

and send it to serial LCD but got an extra weird character at the end.

ABC 123 will display as ABCÆ 123Æ

This is my code.

void supply_get_code() {
  char line[25];
  int n;
  SdFile rdfile("supply.txt", O_READ);
  if (!rdfile.isOpen()) {
    error("error reading supply.txt file");
  }
  while ((n = rdfile.fgets(line, sizeof(line))) > 0) {
    if (line[n - 1] == '\n') {
      counter++;
      if (counter == usedcounter) {
        b=line;
      }
    }
  }
  counter = 0;
  Serial.println(b);
  rdfile.close();

How can I get rid of those weird characters?

BR

If it was my program having that problem, I would print the line in HEX on the serial monitor, so I could see exactly what the character is.

Paul

Hi Paul,

Can you tell me how to do it? I tried

lcd.print(b, HEX);

But give me error when compiling.

exit status 1
Arduino: 1.8.6 (Windows 7), Board: "Arduino/Genuino Uno"

C:\Users\Desktop\Downloads\web\web.ino: In function 'void loop()':

web:370:25: error: no matching function for call to 'LiquidCrystal_I2C::print(String&, int)'

lcd.print(b, HEX);

^

Did I missed something?

Kasamiko:
Did I missed something?

No idea. We do miss your complete code, though.

The variable line is a character array; the variable b is what? From the error message in reply #2, it's a String object. From the code in the opening post, I suspect it to be a character pointer.

You'll have to iterate over b if you want to print every single byte.

sterretje:
No idea. We do miss your complete code, though.

The variable line is a character array; the variable b is what? From the error message in reply #2, it's a String object. From the code in the opening post, I suspect it to be a character pointer.

You'll have to iterate over b if you want to print every single byte.

Hi sterretje, sorry for the late reply.

This is what I'm trying to accomplish. I have a TXT file save on micro SD in this format

ABC 123
DEF 456

and I want to read and display it on LCD one line at at time.
But instead of getting ABC 123, I've got ABCÆ 123Æ with extra weird character .

BTW: b=line;