I got the Segmentation fault error with the following code to
concatenate two strings without using string library functions.
void string_concat()
{
int len1,len2,i,j;
char inpt_str1[30],inpt_str2[30],concat_str[60];
/*Input string1 and calculate its length */
printf("\nEnter the String 1 : \n");
scanf("%s",inpt_str1);
for(i=0;inpt_str1[i]!='\n';i++)
{
len1+=1;
concat_str[i]=inpt_str1[i];
}
/*Input string2 and calculate its length */
printf("\nEnter the String 2 : \n");
scanf("%s",inpt_str2);
for(i=0;inpt_str2[i]!='\n';i++)
{
len2+=1;
}
for(i=len1,j=0;i<=(len1+len2);i++,j++)
{
concat_str[(i+1)]=inpt_str2[j];
}
printf("\nThe Concatenation of Two strings is : %s",concat_str);
}
[TEX]Program received signal SIGSEGV, Segmentation fault.
0x0804877b in string_concat () at str.c:95
95 concat_str[(i+1)]=inpt_str2[j];[/TEX]
I don't know how to rectify the mistake?.