diff --git a/include/input.h b/include/input.h index cdbb432..469b2df 100644 --- a/include/input.h +++ b/include/input.h @@ -5,7 +5,7 @@ typedef struct input_args_t { - char *out; + int *out; bool *alive; } InputArgs; diff --git a/src/input.c b/src/input.c index e6bb53b..8f1f857 100644 --- a/src/input.c +++ b/src/input.c @@ -1,10 +1,17 @@ #include "input.h" #include #include +#ifdef WIN32 +#include +#else #include #include +#endif -char getch(void) +#ifdef WIN32 +#define getch _getch +#else +int getch(void) { char buf = 0; struct termios old = { 0 }; @@ -19,12 +26,13 @@ char getch(void) old.c_lflag |= ICANON; // local modes = Canonical mode old.c_lflag |= ECHO; // local modes = Enable echo. if (tcsetattr(0, TCSADRAIN, &old) < 0) perror ("tcsetattr ~ICANON"); - return buf; + return (int)buf; } +#endif int input(void *vargp) { - char *out = ((InputArgs *)vargp)->out; + int *out = ((InputArgs *)vargp)->out; bool *alive = ((InputArgs *)vargp)->alive; while (*alive) diff --git a/src/main.c b/src/main.c index ac85c3e..78f88bf 100644 --- a/src/main.c +++ b/src/main.c @@ -44,7 +44,7 @@ int main(int argc, char **argv) Food food = generateFood(player); bool *running = malloc(sizeof(bool)); *running = true; - char *key = malloc(sizeof(char)); *key = 0; + int *key = malloc(sizeof(char)); *key = 0; bool stopped = false; InputArgs input_args = (InputArgs){ key, running };