Be sure to use code tags, and that your code is neatly formatted and indented.
Code:
#include <stdio.h>
#include <string.h>
#include <conio.h>
#include <stdlib.h>
void stringMerge(char*, char*, int n);
int main()
{
char *strA, *strB;
int insert_pos;
strA = (char *)malloc(3);
strB = (char *)malloc(3);
printf("enter the first string\n");
gets(strA);
printf("enter the second string\n");
gets(strB);
printf("enter the insert pos of the string\n"); //
scanf("%d", &insert_pos);
stringMerge(strA,strB,insert_pos);
}
void stringMerge(char *a,char *b ,int n)
{
int newString_lenth = strlen(a) + strlen(b) + 1;
char* newString = (char*)malloc(newString_lenth);
strncpy(newString, a, n);
newString[n] = '\0';
strcat(newString, b);
strcat(newString, a + n);
printf("%s\n", newString);
getch();
}
You're only allocating enough space for 3 characters, one of which must be the string-terminating null character '\0'. You should use a reasonably large size if you don't know what the length of the input would be.
Additional comments: