debounce working strange

Hello there,
i want to write a code for my mega to print on serial which pushbutton was pressed from a number of 24 buttons,but my debouncing code works very strange.

this is my code:

int buton[] = {22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45};

void setup() {
  Serial.begin(9600);
  Serial1.begin(9600);
  for (int i = 0; i < 24; i++) {
    pinMode(buton[i], INPUT);
  }
} // end of setup()

void loop() {
  ButtonDebounce();
} // end of loop()


void ButtonDebounce(void)
{
  char led[12] = {0};
  static byte buttonState[24]     = {0};   // the current reading from the input pin
  static byte lastButtonState[24] = {0};   // the previous reading from the input pin

  // the following variables are long's because the time, measured in miliseconds,
  // will quickly become a bigger number than can be stored in an int.
  static long lastDebounceTime[24] = {0};  // the last time the output pin was toggled
  long debounceDelay = 50;         // the debounce time; increase if the output flickers

  byte reading[24];

  for (int i = 0; i < 24; i++) {
    reading[i] = digitalRead(buton[i]);
  }


  for (int i = 0; i < 24; i++) {
    if (reading[i] != lastButtonState[i]) {
      // reset the debouncing timer
      lastDebounceTime[i] = millis();
    }

    if ((millis() - lastDebounceTime[i]) > debounceDelay) {
      // whatever the reading is at, it's been there for longer
      // than the debounce delay, so take it as the actual current state:

      // if the button state has changed:
      if (reading[i] != buttonState[i]) {
        buttonState[i] = reading[i];

        // only toggle the LED if the new button state is HIGH
        if (buttonState[i] == HIGH) {
          
          sprintf(led, "<%d>", i);
          Serial1.println(led);
          Serial.println(led);
        }
      }
    }
  } // end for() loop
  // save the reading.  Next time through the loop,
  // it'll be the lastButtonState:
  for (int i = 0; i < 24; i++) {
    lastButtonState[i] = reading[i];
  }
} // end of ButtonDebounce()

and when i push a button it shows on serial that i have pushed 2, 3 or 4 buttons:

<1>
<2>
<3>
<3>
<4>
<3>
<4>
<8>
<0>
<1>
<2>
<3>
<4>
<6>
<5>

i pushed the same button 3 or 4 times.

can you tell me what have i done wrong? or at least help me achieve my goal in another way…

All your inputs are floating:

  for (int i = 0; i < 24; i++) {
    pinMode(buton[i], INPUT);
  }

try INPUT_PULLUP mode.