home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / qc / qc25 / input.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-11-15  |  869 b   |  38 lines

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