Skip to content

Commit 1a7fd17

Browse files
Merge pull request seeditsolution#231 from param-dev/patch-1
Create concatenate str
2 parents d478fc6 + 29a8c5e commit 1a7fd17

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

concatenate str

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include <stdio.h>
2+
int main() {
3+
char s1[100] = "programming ", s2[] = "is awesome";
4+
int length, j;
5+
6+
// store length of s1 in the length variable
7+
length = 0;
8+
while (s1[length] != '\0') {
9+
++length;
10+
}
11+
12+
// concatenate s2 to s1
13+
for (j = 0; s2[j] != '\0'; ++j, ++length) {
14+
s1[length] = s2[j];
15+
}
16+
17+
// terminating the s1 string
18+
s1[length] = '\0';
19+
20+
printf("After concatenation: ");
21+
puts(s1);
22+
23+
return 0;
24+
}

0 commit comments

Comments
 (0)