I have two strings, str1 and str2. I want the concatenation of them on a space in the heap. I malloc space for them using:
char *concat = (char*) malloc(strlen(str1) + strlen(str2) + 1);
Can I just do:
strcat(concat, str1);
strcat(concat, str2);
And concat will give me the place on the heap with the two strings concatted? I am asking because it seems that strcat would actually add the str1 to the end of the space allocated using malloc. Is this correct? So, then, str1 would appear at position strlen(str1) + strlen(str2) + 1.
The reason that I am asking is that I am using the method above, but I am getting an error in valgrind: Conditional jump or move depends on uninitialised value(s)