0

when i run the following code i don't get any issues

int main(){
    char charr[] = "hallo you my name is :  \0";

    char *charName = "name \0";

    mystrcat(charr,charName);
}

void mystrcat(char *s,char *t) {
    while(*s!='\0')
        s++;
    s--;                      /* goes back to \0 char */
    while((*s=*t)!='\0')
    {
        s++;
        t++;
    }
}

but when running the following code which does the same thing i get "Dumping stack trace to file.exe.stackdump" error

int main(){
    char *charr = "hallo you my name is :  \0";

    char *charName = "name \0";

    mystrcat(charr,charName);
}

void mystrcat(char *s,char *t) {
    while(*s!='\0')
        s++;
    s--;                      /* goes back to \0 char */
    while((*s=*t)!='\0')
    {
        s++;
        t++;
    }
}

can anyone give me an explanation on why this happening?

Federico klez Culloca
  • 26,308
  • 17
  • 56
  • 95

0 Answers0