/* * concat.c * * Created on: 6 июл. 2022 г. * Author: alexander */ #include "concat.h" #include #include #include char* concat(char *s1, char *s2) { size_t len1 = s1 ? strlen(s1) : 0; size_t len2 = s2 ? strlen(s2) : 0; char *result = (char *)malloc(sizeof(char) * (len1 + len2 + 1)); if (!result) { fprintf(stderr, "malloc() failed: insufficient memory!\n"); return NULL; } if (s1) { strncpy(result, s1, (len1 + 1)); } if (s2) { strncpy(result + len1, s2, (len2 + 1)); } return result; }