Please, have a look at this: http://question.onlinegdb.com/7745/whats-a-good-getkey-function-to-use
Note: it's quite similar to what you did in http://question.onlinegdb.com/8060/hey-guys-i-need-some-help-with-my-snek-program-on-c