forked from sgreenlee/C-Primer-Plus-Exercises
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexercise06.c
42 lines (33 loc) · 755 Bytes
/
exercise06.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
36
37
38
39
40
41
42
// C Primer Plus
// Chapter 7 Exercise 6:
// Write a program that reads input up to # and reports the number of times that the
// sequence ei occurs.
#include <stdio.h>
#include <stdbool.h>
#include <ctype.h>
#define STOP '#'
int main(void)
{
char ch;
unsigned int ei_count = 0;
bool e_flag = false;
printf("This program reads input and counts the number of times the\n"
"sequence 'ei' occurs (case insensitive).\n");
printf("Enter input (%c to stop):\n", STOP);
while ((ch = getchar()) != STOP)
{
ch = tolower(ch);
if (ch == 'e')
e_flag = true;
else if (ch == 'i')
{
if (e_flag)
ei_count++;
e_flag = false;
}
else
e_flag = false;
}
printf("The sequence 'ei' occurs %u times.\n", ei_count);
return 0;
}