Ryan Haining :
A series of strcpy()s gets what you need\n\nsize_t len1 = strlen(s1);\nsize_t len2 = strlen(s2);\n\nchar* res = malloc(len1 * (len2+1) + 1);\nres[0] = '\\0';\nsize_t pos = 0;\nfor (const char *p = s1; *p; ++p, pos += (len2+1)) {\n // append s2 to the string\n strcpy(&res[pos], s2);\n // append the next character\n strncpy(&res[pos+len2], p, 1);\n // add the NUL\n res[pos+len2+1] = '\\0';\n}\nputs(res);\n\n\nThis could be done with less code with strcat but that would require walking the string on each call.",
2016-09-20T18:56:52