Char array adds a whole other char array.

I'm reading information from an RFID tag, and I get this data from it: 01 251039 2# 01 - Status of RFID 25 - The weight I've written onto ut. (Yes, there are two spaces) 1039 - ID 2 - The type (three spaces.

char IDString[4];
char weightString[4];
char type;
float amount = 0;

void loop()
{
  RFID_Buffer();
  Serial.println(IDString);
  Serial.println(weightString);
  Serial.println(type);
  Serial.println(amount);
}


void RFID_Buffer()
{
    String stringBuffer;
    char charBuffer[16];
    Serial1.println("SR1000003#");
    delay(100);
    stringBuffer = Serial1.readString();
    stringBuffer.toCharArray(charBuffer,16);
    Serial.println(charBuffer);
    if(charBuffer[2] == '#'){
      //No data or no chip
    }
    else{
      weightString[0] = charBuffer[2];
      weightString[1] = charBuffer[3];
      weightString[2] = charBuffer[4];
      weightString[3] = charBuffer[5];
      
      IDString[0] = charBuffer[6];
      IDString[1] = charBuffer[7];
      IDString[2] = charBuffer[8];
      IDString[3] = charBuffer[9];
      
      type = charBuffer[13];

      amount = atof(weightString);
      digitalWrite(RFIDOK,HIGH);
      RFIDDone = true;
    } 
  //01  251039   2#
}

This is what I get on the monitor:

1039 251039 2 251039.00

As you can see, the weightString adds the IDString. This messes up the whole program, so why?

  RFID_Buffer();

Good function names have a noun and a verb - some action to be performed on some object. Are you trying to buffer and RFID? Or, are you trying to RFID a buffer?

Rename this function!

    String stringBuffer;

You do NOT need Strings. A buffer is an array. The String is NOT an array, so it can not POSSIBLY be a buffer.

    stringBuffer.toCharArray(charBuffer,16);

You do NOT have room to store 16 characters in a 16 element array. You MUST leave room for the NULL.

None of your char arrays (weightString or IDString) are strings. Do not pass char arrays to functions that expect strings.

A string is a char array THAT IS NULL TERMINATED!. Your char arrays are not strings.

You forget to add the '\0' at the end of your small strings (char buffers) as they are consécutive in memory you print through until by luck you hit a zero byte

You are not creating c-strings as you're missing string terminators for your character strings. E.g. char IDstring[4] should be char IDstring[5] and and the last element should be '\0'.

    String stringBuffer;

You do NOT need Strings. A buffer is an array. The String is NOT an array, so it can not POSSIBLY be a buffer.

The RFID uses String, I can't just use a char array.

I tried changing RFID_Buffe() to:

void RFID_Buffer()
{
    String stringBuffer;
    char charBuffer[17];
    Serial1.println("SR1000003#");
    delay(100);
    stringBuffer = Serial1.readString();
    stringBuffer.toCharArray(charBuffer,16);
    Serial.println(charBuffer);
    if(charBuffer[2] == '#'){
      //No data or no chip
    }
    else{
      weightString[0] = charBuffer[2];
      weightString[1] = charBuffer[3];
      weightString[2] = charBuffer[4];
      weightString[3] = charBuffer[5];
      weightString[4] = '\0';
      
      IDString[0] = charBuffer[6];
      IDString[1] = charBuffer[7];
      IDString[2] = charBuffer[8];
      IDString[3] = charBuffer[9];
      IDString[4] = '\0';
      
      type = charBuffer[13];

      amount = atof(weightString);
      digitalWrite(RFIDOK,HIGH);
      RFIDDone = true;
    } 
  //01  251039   2#
}

Did you also change change those?

char IDString[4];
char weightString[4];

sterretje: Did you also change change those?

char IDString[4];
char weightString[4];

No, I didn't.. Rookie mistake. Everything works now! Thanks too all of you! :D

The RFID uses String, I can't just use a char array.

NOT true. You do NOT need to use Serial1.readString() to get the data from the RFID. You can use Serial1.available() and Serial1.read() to read the data, until the end of packet marker arrives.