Originally Posted by
Brokenhope
Create a bool such as: lastCharWas and set it to false initially. Then when you find the first character you are looking for set it to true. Then when looking for the next character, if 'lastCharWas' is true, and the next character is whatever, increment the count. Then set 'lastCharWas' to false.
Thanks for the tip. I couldnt get the bool function to work so i used int set to 0 or 1. Here is my code now but its just counting the "s". Am I barking up the right tree?
Off to find dinner. I'll check back after my belly quits complaining!
Code:
#include <stdio.h>
int main(void)
{
char ch;
int is_count = 0;
int lastchar = 0;
printf("Key in your word or phrase: \n");
while ((ch = getchar()) !='#')
{
if (ch == 'i')
lastchar = 1;
if (ch == 's' && lastchar == 1)
is_count++;
}
lastchar = 0;
printf("\"is\" count %d\n", is_count);
getchar();
getchar();
return 0;
}