home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / c / other / learn / rdkeybrd.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-10-10  |  860 b   |  39 lines

  1. /* INPUT.C: Reads keyboard. */
  2.  
  3. #include <stdio.h>
  4. #include <conio.h>
  5. #include <ctype.h>
  6.  
  7. main()
  8. {
  9.    int num;
  10.    char c;
  11.    char name[80];
  12.    float rb;
  13.  
  14.    puts( "** Type \"Name:\" and your name" );
  15.    scanf( "Name: %40s", name );
  16.    printf( "** You typed this:\n%s", name );
  17.    puts( "\n\n** Try again, with the gets function." );
  18.    fflush( stdin );
  19.    gets( name );
  20.    printf( "** You typed this:\n%s\n", name );
  21.  
  22.    printf( "\n** Now type an integer.\n" );
  23.    scanf( "%i", &num );
  24.    sprintf( name, "** You typed this number: %i\n", num );
  25.    puts( name );
  26.  
  27.    fflush( stdin );
  28.    printf( "** Enter a floating-point value.\n" );
  29.    scanf( "%f", &rb );
  30.    printf( "** The answer is %f or %e\n", rb, rb );
  31.  
  32.    printf( "** Continue? Y or N\n" );
  33.  
  34.    do
  35.       c = tolower( getch() );
  36.    while( c != 'y' && c != 'n' );
  37.  
  38. }
  39.