If i want to concatenate 2 strings in C, do i have to allocate an extra null char for every string or one is enough?
int main(){
char *s1 = NULL;
char *s2 = NULL;
char *s1_s2 = NULL;
s1 = malloc(sizeof(char) * strlen("string1") + 1);
strcpy(s1, "string1");
s2 = malloc(sizeof(char) * strlen("string2") + 1);
strcpy(s2, "string2");
s1_s2 = malloc(sizeof(char) * (strlen(s1) + strlen(s2)) + 2); // shouldn't it be only 1 null char ?
strcpy(s1_s2, s1);
strcat(s1_s2, s2);
}
in this question, they use 2 null bytes for each string. Can some one shed some light? Thanks