一个字符串内容的替换 没有要求的字符要返回error

我这个程序的目的输入一个字符串把其中的her换成she,但是我想,如果没有出现her,返回一个error,应该怎么加一个提示

include<stdio.h>

include<string.h>

void replace(char *p)
{
int i;
while(p!='\0')
{
if(p=='h'&&(p+1)=='e'&&
(p+2)=='r')
{
*p='s';
*(p+1)='h';
*(p+2)='e';
}
p++;
}
}
int main(void)
{
char p[100];
printf("input p:\n");
gets(p);
replace(p);
puts(p);
return 0;

}

include<stdio.h>
include<string.h>
int replace(char *p)
{
  int i;
  int find = 0;
  while(p!='\0')
  {
    if(p=='h'&&(p+1)=='e'&&(p+2)=='r')
    {
      *p='s';
      *(p+1)='h';
      *(p+2)='e';
      find++;
    }
    p++;
  }
  return find;
}
int main(void)
{
  char p[100];
  printf("input p:\n");
  gets(p);
  int find = replace(p);
  if(find == 0)
    printf("error\n");
  puts(p);
  return 0;

}

你题目的解答代码如下:(如有帮助,望采纳!谢谢! 点击我这个回答右上方的【采纳】按钮)

#include <stdio.h>
#include <string.h>
int replace(char *p)
{
    int i,f=0;
    while (*p != '\0')
    {
        if (*p == 'h' && *(p + 1) == 'e' && *(p + 2) == 'r')
        {
            *p = 's';
            *(p + 1) = 'h';
            *(p + 2) = 'e';
            f = 1;
        }
        p++;
    }
    return f;
}
int main(void)
{
    char p[100];
    printf("input p:\n");
    gets(p);
    if (replace(p))
        puts(p);
    else
        printf("error");
        
    return 0;
}


修改完善如下,供参考:

#include<stdio.h>
#include<string.h>

int replace(char *p)//void replace(char *p)
{
    while(*p!='\0')//while(p!='\0')
    {
         if(*p=='h' && *(p+1)=='e' && *(p+2)=='r')//if(p=='h'&&(p+1)=='e'&&(p+2)=='r')
         {
               *p='s';
               *(p+1)='h';
               *(p+2)='e';
         }
         else  return 0;
         p++;
    }
    return 1;
}
int main(void)
{
     char p[100];
     printf("input p:\n");
     gets(p);
     if(replace(p))  puts(p);
     else            puts("error!");
     
     return 0;
}