[comp.lang.c] Input Problem

acs60222@zach.fit.edu ( ENRIQUEZ) (08/05/89)

I am attempting to get single character input for a menu function.
My problem is that the '\n' character ALWAYS gets put into the
buffer (?), so that if the input character is not valid, funny things
happen...

Is there a easy way to "strip" the undesired character from the getchar()
fuction.  Program example:

char foobar_menu ();
{
   char choice;  

   do {
      printf (" ....menu stuff....");
      printf ("Command: );
      choice = getchar();
      }
   while (choice !valid);
   return (choice);
}

This works fine if choice is valid.  However, if choice not valid, the
menu is printed twice.  While I can live with this, I would rather not.
Any help will be appreciated...

mark enriquez    acs60222@zach.UUCP