I wrote the header.h and header.c
The function
get_key()
is returning the key that has been pressed, worked fine when i put the enum and the function decleration/implemention all in themain()
file, but when i tried to seperate to two files, here's what happened.
header.h
enum key
{
UP_KEY,
DOWN_KEY,
LEFT_KEY,
RIGHT_KEY,
INVALID,
ENTER,
NONE
};
key get_key();
HEADER.c
#include "header.h"
key get_key()
{
int ch;
if (kbhit())
{
ch = getch();
ch == 0 || ch == 224;
switch (ch)
{
case 0:
case 224:
switch (getch())
{
case 72:
return UP;
case 80:
return DOWN;
case 75:
return LEFT;
case 77:
return RIGHT;
default:
return INVALID;
}
case 56:
return UP;
case 50:
return DOWN;
case 52:
return LEFT;
case 54:
return RIGHT;
case 13:
return ENTER;
default:
return INVALID;
}
}
return NONE;
}
Two problems.
- In the header.h, at the function declaration, the compiler says that
key
is not defined, which is strange considering thekey
is declared asenum
just 2 lines above. - In the
.c
file,enum key
is also not defined, which is also strange as I wrote#include <header.h>
.
What could be the solution?