Is there any function/common method for concatenation between two string, while string2 appears in string1 in a specified place?
No, there isn't.
You can accomplish what you are trying using many approaches. One approach would be to use sprintf
.
char str[100];
sprintf(str,"I %s love Gyros", "don't");
Another approach would be to shift the contents of str
to the right by the amount you need, and then set the values of the intermediate elements.
#include <stdio.h>
#include <string.h>
void insertInString(char* str1, size_t pos, char const* str2)
{
size_t len1 = strlen(str1);
size_t len2 = strlen(str2);
size_t i = 0;
// Shift the contents of str1
for ( i = len1; i >= pos; --i )
{
str1[i+len2] = str1[i];
}
// Now place the contents of str2 starting from pos
for ( i = 0; i < len2; ++i )
{
str1[i+pos] = str2[i];
}
}
int main()
{
char str[100] = "I love Gyros";
insertInString(str, 2, "don't ");
printf("%s\n", str);
return 0;
}