/* 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 <stdio.h>
#include <stdlib.h>
#include <string.h>

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()
{
   char line[100];
   printf("Enter: ");
   gets(line);
   replace(line, "kat", "hund");
   replace(line, "mis", "vovse");
   printf("%s\n",line);
   return 0;
}
