Use C function
strstr or you can change the program the following way
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
|
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
char ar[20];
unsigned int found = 0;
unsigned int count = 0;
cout << "Enter the array\n";
gets( ar );
for ( char *p = ar; *p; ++p )
{
switch ( *p )
{
case 't' : case 'T' :
found = 1;
break;
case 'h' : case 'H' :
if ( found ) ++found;
break;
case 'e' : case 'E':
if ( found == 2 ) count++;
found = 0;
break;
default:
found = 0;
break;
}
}
cout << count;
return 0;
}
|
EDIT: Also I think you do not understand what happens in the statement of your original program
cout<<("%d",vowc);
Though this statement works however it has no any sense that is there is no any sense to use the comma operator. You should write simply
cout << vowc;
Last edited on
Thanx alot dear you did it right & I will keep in mind the comma use next time.
However the suggested code contains a bug! :) Shall be
1 2 3 4 5 6 7 8
|
case 'h': case 'H':
if ( found == 1 ) ++found;
else found = 0;
break;
case 'e': case 'E':
if ( found == 2 ) count++;
found = 0;
break;
|
Last edited on
Also instead of gets it is better to use cin.getline( ar, sizeof( ar ) );