I m trying to code a function that finds a specafic char in a string and add to it a another char but i get weird result i dont know why
Code:
#include <stdio.h>
#define DEL_IT(P,N)P[N]=0
void copy_safe(char *name,char *buffer,int start)
{
     int i,x=0;
     for(i=start;name[x]=buffer[i];x++,i++);
}
void adv_strcat(char *buffer)
{
     int x=0,i;
     char *save;
     for(i=0;buffer[i]!=0;i++) {
         if(buffer[i]=='\')) {
             save=malloc(sizeof(char) * (100));
             x++;
             }
         if(x==1)
          {
             x=0;
             copy_safe(buffer,save,i);
             DEL_IT(buffer,i);
             strcat(buffer,"\");
             strcat(buffer,save);
             free(save);
          }
      }
}
int main(void)
{
    char name[]="D:\program\program.com";
    adv_strcat(name);
    puts(name);
    getchar();
    return 0;
}
when i coded it it seemed pretty logical the adv_strcat
read the string
if we found a char we looking for we
increment x
then we check if x==1
if it is we reset it back to 0
then we copy the string from that place so we put it again l8er one after we deleted it
then del the string
then reput the save then free it
then repeat the process untill there no more stuff char we searching for

that was its english explaination before i did it i dunno why it failed .