I want to write a program that gets the first half of a string 'ch1' and puts it in a string 'ch3' then gets the first half of another string 'ch2' and concatenates it in 'ch3' "puts is in the end of ch3" but when I execute it, it gives me weird output for ch3 .. for example :
ch1 ="123"
ch2 ="azertyuiop"
the result : ch3 ="1<3rdweirdletter>azert"
This is my code :
int main()
{
char ch1[200],ch2[200],ch3[200];
puts("give 'ch1' ");
gets(ch1);
puts("give 'ch2' ");
gets(ch2);
strncpy(ch3,ch1, strlen(ch1)/2 );
strncat(ch3,ch2, strlen(ch2)/2 );
printf("a half \"%s\" + a half \"%s\" gives \"%s\"",ch1,ch2,ch3);
return 0;
}
I would appreciate if someone helps me. Thanks