home *** CD-ROM | disk | FTP | other *** search
/ C by Discovery (4th Edition) / C_By_Discovery_4th_Edition.tar / C_By_Discovery_4th_Edition / _DISK_ / ch10 / retval.c < prev    next >
C/C++ Source or Header  |  2005-06-16  |  1KB  |  32 lines

  1. /*               retval.c
  2.  *
  3.  *   Synopsis  - Requests and accepts input of a string, an int, a
  4.  *               char, and a float.  Echoes those quantities and
  5.  *               displays return values of printf() and scanf().
  6.  *
  7.  *   Objective - To allow the reader to experiment with input to
  8.  *               scanf() to get a feel for when and how conversions
  9.  *               are made and what feedback is provided by scanf().
  10.  */
  11.  
  12. /* Include Files */
  13. #include <stdio.h>
  14.  
  15. /* Constant Definitions */
  16. #define BUF_SIZE  80
  17.  
  18. int main( void )
  19. {
  20.      char charvar, buff[BUF_SIZE];
  21.      int intvar, printret, scanret;
  22.      float floatvar;
  23.  
  24.      printf( "Enter a string, an int, a character, and a float: " );
  25.                                                                  /* Note 1 */
  26.      scanret = scanf( "%s%d%c%f", buff, &intvar, &charvar, &floatvar );
  27.                                                                  /* Note 2 */
  28.      printret = printf( "Values : %s, %d, |%c|, %5.3f\n", buff, intvar, charvar, floatvar );
  29.      printf( "printret %d, scanret %d\n", printret, scanret );
  30.      return 0;
  31. }
  32.