fork download
  1. #include <assert.h>
  2. #include <ctype.h>
  3. #include <inttypes.h>
  4. #include <limits.h>
  5. #include <stdio.h>
  6.  
  7. int main(void)
  8. {
  9. // count chars
  10. uintmax_t count_lower = 0, count_upper = 0;
  11. for (int c; (c = getchar()) != EOF; ) {
  12. assert(c >= 0 && c <= UCHAR_MAX); // otherwise UB in ctype functions
  13. if (isupper(c)) // C locale
  14. ++count_upper;
  15. else if (islower(c))
  16. ++count_lower;
  17. }
  18. printf("upper: %ju, lower: %ju\n", count_upper, count_lower);
  19. return !feof(stdin); // success on eof
  20. }
  21.  
Success #stdin #stdout 0s 10304KB
stdin
abc ABCD
stdout
upper: 4, lower: 3