Hi all,
I wrote the following program to insert one string into another at a location specified by an integer n.
The program compiles without errors but does not produce the desired results, just outputs : hello, when I want it to output heltherelo
Please let me know waht I am doing wrong.
Thanks a lot.


#include<stdio.h>

void main(void)
{
void insertstring (char str1[], char str2[], int n);
char str1[] = {"hello"};
char str2[] = {"there"};
int n = 4;
int i;

insertstring("hello", "there", 3);
printf("%s\n", str1);
}

void insertstring (char str1[], char str2[], int n)
{
int i, j, x, len1;
char tmp[20];
len1 = strlen(str1);


/*copy str1 into tmp*/
for(i = n, x = 0; i <= len1; i++, x++)
tmp[x] = str1[i];

/*copy str2 into str1*/
for(j = 0; str2[j] != '\0'; j++)
str1[n + j] = str2[j];

str1[n + j + x] = '\0';
}