Concatenating string in C | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
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; }

28th Sep 2017, 3:27 PM
Shantanu Shinde
Shantanu Shinde - avatar
1 Antwort
0
pls answer
29th Sep 2017, 1:54 AM
Shantanu Shinde
Shantanu Shinde - avatar