编写一个C语言程序,用给定的字符串替换文件中的目标字符串,并显示输出替换的个数。

若文件为:
There are moments in life when you miss someone so much that you just want to pick them from your dreams and hug them for real!

样例输入:
you they
样例输出:
3
There are moments in life when they miss someone so much that they just want to pick them from theyr dreams and hug them for real!

请各位大佬看一下这个有什么比较简便的方法来解决吗?(C语言)

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAXSIZE 300
int str_replace(char * str1, char * str2, char * str3);

int main(){
    char str1[MAXSIZE];
    char str2[MAXSIZE];
    char str3[MAXSIZE];
    gets(str1);
    scanf("%s %s",&str2,&str3);
    int num=str_replace(str1, str2, str3);
    printf("%d\n",num);
    printf("%s\n",str1);
    return 0;
}

int str_replace(char * str1, char * str2, char * str3){
    int i, j, k, done, count = 0, gap = 0,num=0;
    char temp[MAXSIZE];
    for(i = 0; i < strlen(str1); i += gap){
        if(str1[i] == str2[0]){
            done = 0;
            for(j = i, k = 0; k < strlen(str2); j++, k++){
                if(str1[j] != str2[k]){
                    done = 1;
                    gap = k;
                    break;
                }
            }
            if(done == 0){
                num++;
                for(j = i + strlen(str2), k = 0; j < strlen(str1); j++, k++){ 
                    temp[k] = str1[j];
                }
                temp[k] = '\0'; 
                for(j = i, k = 0; k < strlen(str3); j++, k++){ 
                    str1[j] = str3[k];
                    count++;
                }
                for(k = 0; k < strlen(temp); j++, k++){ 
                    str1[j] = temp[k];
                }
                str1[j] = '\0'; 
                gap = strlen(str2);
            }
        }else{
            gap = 1;
        }
    }
    if(count == 0){
        printf("Can't find the replaced string!\n");
    }
    return num;
}