// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
#include <cstdlib>
#include <cstring>

#include <fstream>

using namespace std;

void replace(char *s,char *s1,char *s2)
{
  int i,j;
  char *tmp;
  tmp = (char *)malloc(strlen(s)+1);
  strcpy(tmp,s);
  i = 0;
  j = 0;
  while(i<strlen(tmp)) {
      if(strncmp(tmp+i,s1,strlen(s1))==0) {
        strcpy(s+j,s2);
        i=i+strlen(s1);
        j=j+strlen(s2);
      } else {
        s[j]=tmp[i];
        i++;
        j++;
      }
  }
  s[j] = '\0';
  free(tmp);
  return;
}

int main()
{
   FILE *fp1,*fp2;
   ifstream f1("input.dat");
   ofstream f2("output.dat");
   while(!f1.eof())
   {
      char line[133];
      if(f1.getline(line,sizeof(line)))
      {
          replace(line,"hund","kat");
          f2 << line << endl;
      }
   }
   return 0;
}
