home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / mbug / mbug150.arc / C-STUFF1.LBR / ARRAY1.C next >
C/C++ Source or Header  |  1979-12-31  |  512b  |  28 lines

  1.  
  2. #include "stdio"
  3.  
  4. main()                /* count digits, white space, other */
  5.  
  6.     {
  7.     int c, i, nwhite, nother;
  8.     int ndigit[10];
  9.  
  10.     nwhite = nother = 0;
  11.     for (i = 0; i < 10; ++i)
  12.         ndigit[i] = 0;
  13.  
  14.     while ((c = getchar()) != EOF)
  15.         if (c >= '0' && c <= '9')
  16.             ++ndigit[c-'0'];
  17.         else if (c == ' ' || c == '\n' || c == '\t')
  18.             ++nwhite;
  19.         else
  20.             ++nother;
  21.  
  22.     printf("digits =");
  23.     for (i = 0; i < 10; ++i)
  24.         printf(" %d", ndigit[i]);
  25.     printf("\nwhite space = %d, other = %d\n",
  26.         nwhite, nother);
  27.     }
  28.