How can i attach one text array to another text array in c on a given position. For example from input user enters 2 arrays and one digit which is the position.
( _ is empty space )
first: hi my name is ,i learn c
second: Jacob_
pos: 14
result hi my name is jacob ,i learn c
here is my code
#include<stdio.h>
#include<string.h>
#include<ctype.h>
void attach(char *a,char *b,char*c,int pos){
int i,j;
for(i = 0; i < pos;i++){
*(c+i) = *(a+i);
}
int lenB = strlen(b);
for(i = pos+1;i < lenB;i++){
*(c+i) = *(b+i);
}
int lenRes = lenB+pos;
int lenA = strlen(a);
for(i = lenRes;i < lenA;i++){
*(c+i) = *(a+i);
}
puts(c);
}
int main()
{
char a[1000],b[1000],c[1000];
gets(a);
gets(b);
int pos;
scanf("%d",&pos);
attach(a,b,c,pos);
return 0;
}