Given a string count number of substring 'hi' and replace 'hi' with 'hey' everywhere. I have written the following code and done all steps right but i am getting error when last character is either h or i. The output is partial correct is this case

#include
#include
using namespace std;
void cou(char *a,int n)
{
int count=0;
int j=0;
int l=1;
while(a[j]!=’\0’)
{
if(a[j]==‘h’)
{
j++;
if(a[j]==‘i’)
{
count++;
}
}
j++;
}
cout<<count<<endl;
}
void rem(char *a,int n)
{
int j=0;
int k=0;
char b[100];
while(a[j]!=’\0’)
{
if(a[j]==‘h’ && a[j+1]==‘i’)
{
j=j+2;
}
b[k]=a[j];
k++;
j++;

}
cout<<b<<endl;

}
void rep(char *a,int n)
{
int j=0;
int k=0;
char b[100];
while(a[j]!=’\0’)
{
if(a[j+1]==’\0’)
{
b[k]=a[j];
k++;
j++;
break;
}
else if(a[j]==‘h’ && a[j+1]!=‘i’ || a[j]!=‘h’)
{
b[k]=a[j];
k++;
j++;
continue;
}

	else if(a[j]=='h' && a[j+1]=='i')
	{
		b[k]='h';
		k++;
		b[k]='e';
		k++;
		b[k]='y';
		k++;
		j=j+2;
	}
	
}
cout<<b;

}
int main() {
char s[100];
cin>>s;
int k=sizeof(s);
cou(s,k);
rem(s,k);
rep(s,k);

return 0;

}

hi anish
save ur code to online ide of coding block then post the link here

anish can u also post the link of question
and also there is one error in code
when u are checking for a[j+1] check wheather j+1 is null or not
because if j==n-1 n=length of string then j+1 is n which is amiguity
this is the problem i have seen

post the link of the question

see test case u have to insert bye not hey