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

  1. /*                            strngio2.c
  2.  *
  3.  *   Synopsis  - Prompts for and accepts a line of text as input
  4.  *               from standard input with the standard library
  5.  *               function fgets(). Echoes the line to standard
  6.  *               output with printf().
  7.  *
  8.  *   Objective - To illustrate string input with fgets().
  9.  */
  10.  
  11. /* Include Files */
  12. #include <stdio.h>                                     /* Note 1 */
  13.  
  14. /* Constant Definitions */
  15. #define BUF_SIZE 512
  16.  
  17. int main( void )
  18. {
  19.      char inputarray[BUF_SIZE];                        /* Note 2 */
  20.      char *inputptr;
  21.  
  22.      printf( "Enter a line of text.\n> " );
  23.      inputptr = fgets( inputarray, BUF_SIZE, stdin );  /* Note 3 */
  24.      if ( inputptr != NULL )                           /* Note 4 */
  25.           printf( inputptr );                          /* Note 5 */
  26.      else
  27.           printf( "error in input\n" );
  28.      return 0;
  29. }
  30.