home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / qc_prog / chap09 / dialog.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-04-07  |  1006 b   |  42 lines

  1. /* dialog.c  -- a conversation using gets() and puts()  */
  2.  
  3. #include <stdio.h>          /* for NULL and BUFSIZ */
  4.  
  5. #define THE_QUESTION \
  6. "And what is your view on the current price of corn\n\
  7. and the stability of our trade import balance?"
  8.  
  9. main()
  10. {
  11.     char name[BUFSIZ],
  12.          buf[BUFSIZ];
  13.     extern char *gets();
  14.  
  15.     name[0] = '\0';         /* clear the name */
  16.  
  17.     puts("\n\nHi there. And what is your name?");
  18.  
  19.     if (gets(name) != NULL && name[0] != '\0')
  20.         {
  21.         printf("\nPleased to meet you, %s.\n", name);
  22.         puts(THE_QUESTION);
  23.  
  24.         /*
  25.          * force an extra <enter> before replying.
  26.          */
  27.         do
  28.             {
  29.             if (gets(buf) == NULL)
  30.                 break;
  31.  
  32.             } while (*buf != '\0');     /* wait for empty line */
  33.  
  34.         puts("Sorry. I needed to think about that.");
  35.         printf("Nice talking to you, %s.\n", name);
  36.         }
  37.     else
  38.         puts("How rude!");
  39.  
  40.     puts("Goodbye.");
  41. }
  42.