0
Concatenating string in C
I wrote this code for concatenating string without lib func. it works fine if both strings are of equal length, but on the length is different, it prints garbage char at end of the concatenated string. pls tell me wats wrng. #include<stdio.h> #include<conio.h> int main() { char S1[100],S2[100],S3[100]; gets(S1); gets(S2); int i,l,j=0,k; for(i=0;S1[i]!='\0';i++); for(k=0;k<S2[k]!='\0';k++); l=i+1; S1[i]=' '; for(i=0;S1[i]!='\0';i++) S3[i]=S1[i]; for(i=l;j<k;i++) { S3[i]=S2[j]; j++; } printf("Concatenated string = %s",S3); return 0; }
1 Réponse
0
pls answer