Split AND convert char array to two separate integers.

This project is to set an alarm by typing in the time on a keypad.

So, I have a 4 digit user input from a 3X3 matrix keypad stored into a char array but I want to split it up into two separate integers, one for hours and one for minutes.

There is a lot of other code but that's all fine so here is my conversion code so far:

char bufferH[2];
char bufferM[2];

bufferH[0] = time[0];
bufferH[1] = time[1];
bufferM[0] = time[2];
bufferM[1] = time[3];

Hcount = atoi(bufferH);
Mcount = atoi(bufferM);
    lcd.clear();
    lcd.home();
  delay(3000);
  lcd.print(Hcount);
  lcd.print("    ");
  lcd.print(Mcount);
  delay(3000);

Lets say I enter 1234 for 12:34 as the time.
It mostly works, only problem is that the output is like this:

"1234 34"

I'm clearly missing something very simple... right guys?

Maybe there is a much MUCH easier way to get the input stored in a variable but I'm a bit of a coding noob so this is all I could think of.

Thank you in advance for your time, hope to hear from someone soon.

atoi() expects the chars to be converted to an integer to be in a null terminated C style string. Yours aren't.