#include <string.h>
#include <stdio.h>
#include <iostream>
using namespace std;

static void replace_string(char *in, string findw, string replacew) {

string s(in);
      
size_t index;
    while ((index = s.find(findw)) != string::npos)
        s.replace(index, findw.length(), replacew);

bzero(in,strlen(in)+1);
strcpy(in,s.c_str());
                
}//replace_string


int main () {

char a[]="HI EVERYBODY";

cout << a << endl;

replace_string(a,"EVERYBODY","MEHDI");

cout << a << endl;


}//main

By: Mehdi Sadighian
Contact: mehdi.sadighian@hotmail.com
TAG: C, C++, replace string, replace char, char array