/*
A demonstration of a do-while loop and a function 
which returns a value.

Ray Ontko  1999/09/30
*/

#include <stdio.h>

int get_first_char() ;

main()
{
int c;

do
  {
  printf( "Enter Y or N.\n" ) ;

  c = get_first_char() ;

  if ( ( c != 'y' ) && ( c != 'n' ) &&
       ( c != 'Y' ) && ( c != 'N' ) )
     printf( "Please enter Y or N!\n\n" ) ;

  } while ( ( c != 'y' ) && ( c != 'n' ) &&
            ( c != 'Y' ) && ( c != 'N' ) ) ;

printf("Thank you!\n") ;
}

/*
int get_first_char()

Returns the first character on a line, and
skips all other characters to the end of line
or end of file, whichever comes first.  If the
first character IS an end of line or end of
file, then THAT character is returned and
no skipping occurs.
*/

int get_first_char()
{
int first ;
int c ;

first = c = getchar() ;
while ( ( c != '\n' ) && ( c != EOF ) )
  c = getchar() ;

return first ;
}
