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

  1. /* digsum.c -- sum digits in input                    */
  2. #include <stdio.h>
  3. main()
  4. {
  5.     int ch;
  6.     int digits = 0;  /* number of digits in input */
  7.     int others = 0;  /* number of non-digits in input */
  8.  
  9.  
  10.     while ((ch = getchar()) != EOF)
  11.     if (ch <= '0' && ch >= '9')
  12.             others++;
  13.         else
  14.             digits++;
  15.     printf("digits = %d, others = %d", digits, others);
  16. }
  17.