I have written a code which takes two strings s1 and s2 from the user and inserts the string s2 into s1 at a location m. But the code is not working properly, especially the first while loop.. can anyone figure out whats wrong...
Code:#include<stdio.h> #include<string.h> void main() { char s1[300],s2[100]; int m;int i,j;int k; printf("Enter string one:"); gets(s1); printf("Enter string 2:"); gets(s2); printf("\nEnter location number:"); scanf("%d",&m); i=strlen(s2); j=strlen(s1)+1; k=m; while(s1[m]) { s1[i+(j++)]=s1[m++]; /* create space for s2 in s1 by shifting the characters in s1 ahead by (i+j) positions from location m */ } s1[i+j]=s1[m]; /* Insert the string terimator */ m=k; i=0; while(s2[i]) { s1[m++]=s2[i++]; /* Copy string s2 into s1 from location m */ } puts(s1); }