home *** CD-ROM | disk | FTP | other *** search
/ Sams Teach Yourself C in 21 Days (6th Edition) / STYC216E.ISO / mac / Examples / AppD / ListD04.c / ListD04.c
Encoding:
C/C++ Source or Header  |  2002-08-11  |  1.1 KB  |  39 lines  |  [TEXT/LMAN]

  1. /*==========================================================*
  2.  * Program: listD04.c                                      *
  3.  * Book:    Teach Yourself C in 21 Days                     *
  4.  *                                                          *
  5.  * Purpose: To use maximum and minimum constants.           *
  6.  * Note:    Not all valid characters are displayable to the *
  7.  *          screen!                                         *
  8.  *==========================================================*/
  9.  
  10. #include <float.h>
  11. #include <limits.h>
  12. #include <stdio.h>
  13.  
  14. int main( void )
  15. {
  16.     unsigned char ch;
  17.     int  i;
  18.  
  19.     printf( "Enter a numeric value.");
  20.     printf( "\nThis value will be translated to a character.");
  21.     printf( "\n\n==> " );
  22.  
  23.     scanf("%d", &i);
  24.  
  25.     while( i < 0 || i > UCHAR_MAX )
  26.     {
  27.        printf("\n\nNot a valid value for a character.");
  28.        printf("\nEnter a value from 0 to %d ==> ", UCHAR_MAX);
  29.  
  30.        scanf("%d", &i);
  31.     }
  32.     ch = (char) i;
  33.  
  34.     printf("\n\n%d is character %c\n", ch, ch );
  35.  
  36.     return 0;
  37. }
  38.  
  39.