#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char *name = "hello";
int main(void) {
char *ext = ".txt";
int len = strlen(name) + strlen(ext) + 1;
char *n2 = malloc(len);
char *n2a = malloc(len);
if (n2 == NULL || n2a == NULL)
abort();
strlcpy(n2, name, len);
strlcat(n2, ext, len);
printf("%s\n", n2);
/* or for conforming C99 ... */
strncpy(n2a, name, len);
strncat(n2a, ext, len - strlen(n2a));
printf("%s\n", n2a);
return 0; // this exits, otherwise free n2 && n2a
}