>void main()
This is incorrect, use should use "int main(void)".
>int key;
>if ((int)key==49)
>here (int)key is typecasts the charcter to int.
Not exactly, key is already an int because that's how is was declared. Therefore the cast isn't necessary.
>if ((int)key==49)
Rather than coding the ASCII value of the character, you could use the character constant, like so:
>if (key=='1')
This makes things easier to read.
>i got that part working but how can i then get it to go to say the game?
Does this example help?:
Code:
#include <stdio.h>
#include <conio.h>
void TheGame(void)
{
printf("The game has been activated\n");
}
int main(void)
{
int key, StillGoing = 1;
while (StillGoing)
{
printf("--- Menu ---\n1.New Game\n2.Exit Game\n>");
switch (key = getch())
{
case '1': TheGame(); break;
case '2': StillGoing = 0; break;
default: printf("Option Invalid: %c\n", key); break;
}
}
printf ("Exiting\n");
return(0);
}