Here's the fun bit: I don't like that code.
It's the last bit that says "NO!" to me:
strcpy(dst,leng);
leng is defined as being the size of the output - but there is no guarantee that dst has that much space - and since you are inserting a chunk of data in the middle of the original content of dst, it is almost certain that it will be longer than t was - which means it may well exceed the space allocated for it. If it does, your code will overwrite subsequent data.
A better approach would be to use malloc to allocate the output area and return it from your function instead of overwriting the original.
There's also the use of
strlen
without understanding what it does: it counts the characters up to the first null and returns that count.
So why do you use it to determine the location to put a terminating null?
leng[strlen(leng)]='\0';
By definition, there is already a null at that location...
It's also a slow operation - so using it twice each time you go round a loop is horribly inefficient, given that neither
src
nor
dst
get modified inside the loop.
I'd do it this way:
1) malloc enough space to hold the output.
2) Use memcpy to copy the first part of dst over.
3) Use memcpy to copy src over.
4) use memcpy to copy the end of dst over.
5) return the new string.
This also means that you can declare it as
char *strinsert(const char *dst, int len, const char *src, int offset)
Which means you can pass constant strings to the function. And it'll be a load quicker!