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 / strwarn.c < prev    next >
C/C++ Source or Header  |  2005-06-16  |  858b  |  30 lines

  1. /*                                strwarn.c
  2.  *
  3.  *   Synopsis  - Attempts to accept input of a line of text with 
  4.  *               the library function fgets().  There is an error
  5.  *               in the program because space for the input line
  6.  *               was not allocated.
  7.  *
  8.  *   Objective - To point out a common error made by beginning C
  9.  *               programmers.
  10.  */
  11. /* Include Files */
  12. #include <stdio.h>
  13.  
  14. /* Constant Definitions */
  15. #define BUFF_SIZE 80
  16.  
  17. int main( void )
  18. {
  19.      char *prompt = "Enter a line of text.\n> ";
  20.      char *inputptr, *inputptr1;                        /* Note 1 */
  21.  
  22.      printf( prompt );
  23.      inputptr1 = fgets( inputptr, BUFF_SIZE, stdin );   /* Note 2 */
  24.      if ( inputptr1 != NULL )
  25.           printf( inputptr1 );
  26.      else
  27.           printf( "Error in input\n" );
  28.      return 0;
  29. }
  30.