char keys[5];
That's one mistake. You can't fit five characters and a null terminator in an array of five characters.