-
Notifications
You must be signed in to change notification settings - Fork 124
/
exercise03.c
35 lines (29 loc) · 953 Bytes
/
exercise03.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// C Primer Plus
// Chapter 8 Exercise 3:
// Write a program that reads input as a stream of characters until
// encountering EOF. Have it report the number of uppercase letters, the number
// of lowercase letters, and the number of other characters in the input. You
// may assume that the numeric values for the lowercase letters are sequential
// and assume the same for uppercase. Or, more portably, you can use
// appropriate classification functions from the ctype.h library.
#include <stdio.h>
#include <ctype.h>
int main(void)
{
int ch;
int uppercase_count = 0, lowercase_count = 0, other_count = 0;
while ((ch = getchar()) != EOF)
{
if (isupper(ch))
uppercase_count++;
else if (islower(ch))
lowercase_count++;
else
other_count++;
}
printf("Character Counts\n");
printf("Uppercase letters: %d\n", uppercase_count);
printf("Lowercase letters: %d\n", lowercase_count);
printf("Other: %d\n", other_count);
return 0;
}