Beginner in C first menu - need critique
Hi, I am very new to C programing and am practicing functions, loops, and user input. So I decided a good way to mix all of that is to make a simple menu. I had a lot of trouble learning how to get user input without a mistake by the user crashing my program. I think I have a good solution my question is this: Is the solution I have come up with a good one? Am I making noob type mistakes here? If so is there any reference material that would help me understand my short comings in this area.
Here is my menu program.
Code:
/*Loop practice Making a menu
This is a simple menu that allows
three choices of destination and
quits when the user hits q
*/
#include <stdio.h>
/* Function templates */
void functone (void);
void functtwo (void);
void functthree (void);
int main ()
{
// set up conditions for the loop
int choice;
char ch;
choice = 0;
// I used a do while loop to insure that it would run once
do{
// print menu
printf ( "Make your choice.\n");
printf ( "1 - 1st program\n" );
printf ( "2 - 2nd program\n" );
printf ( "3 - 3rd program\n" );
printf ( "q to quit\n");
// get user input and clear out stdin
choice = getchar ();
// this part clears the stdin of leftovers
ch = getchar ();
while ( ch != '\n' ) ch = getchar ();
// Call the desired function
if (choice == 49 ) {
functone ();
}
if (choice == 50 ) {
functtwo ();
}
if (choice == 51 ) {
functthree ();
}
}
// Check for escape code
while ( choice != 113);
// just to verify I finished
printf ( "Done\n");
return 0;
}
// The first called function on the menu
void functone (void)
{
printf ( "You chose one\n");
}
// The second called function on the menu
void functtwo (void)
{
printf ( "You chose two\n");
}
// The third called function on the menu
void functthree (void)
{
printf ( "You chose three\n");
}