home *** CD-ROM | disk | FTP | other *** search
/ C by Discovery (4th Edition) / C_By_Discovery_4th_Edition.tar / C_By_Discovery_4th_Edition / _DISK_ / ch4 / pointer2.c < prev    next >
C/C++ Source or Header  |  2005-06-16  |  940b  |  29 lines

  1. /*                       pointer2.c 
  2.  *
  3.  *   Synopsis  - Accepts input of a single character entered 
  4.  *               from the keyboard and prints the entered value 
  5.  *               unless it was a newline.
  6.  *
  7.  *   Objective - Illustrates use of NULL and relational
  8.  *               expressions with pointers.
  9.  */
  10.  
  11. /* Include Files */
  12. #include <stdio.h>                              /* Note 1 */
  13.  
  14. int main( void )
  15. {
  16.      int c, *input_ptr = &c;                    /* Note 2 */
  17.  
  18.      printf( "Please enter a character from the keyboard" );
  19.      printf( " or press return.\n" );
  20.  
  21.      if ( ( *input_ptr = getchar() ) == '\n' )  /* Note 3 */
  22.           input_ptr = NULL;                     /* Note 4 */
  23.  
  24.      if ( input_ptr == NULL )                   /* Note 5 */        
  25.           printf( "Just a return was typed.\n" );
  26.      else            
  27.           printf( "The character %c was entered.\n", *input_ptr );
  28.      return 0;
  29. }