- Learn C By Examples Time
- Learn C by Examples - Home
- C Examples - Simple Programs
- C Examples - Loops/Iterations
- C Examples - Patterns
- C Examples - Arrays
- C Examples - Strings
- C Examples - Mathematics
- C Examples - Linked List
- C Programming Useful Resources
- Learn C By Examples - Quick Guide
- Learn C By Examples - Resources
- Learn C By Examples - Discussion
Program to Concatenate Strings in C
Implementation
Now, we shall see the actual implementation of the program −
#include <stdio.h> #include <string.h> int main() { char s1[10] = "Taj"; char s2[] = "Mahal"; int i, j, n1, n2; n1 = strlen(s1); n2 = strlen(s2); j = 0; for(i = n1; i< n1+n2; i++ ) { s1[i] = s2[j]; j++; } s1[i] = '\0'; printf("%s", s1); return 0; }
Output
Output of this program should be −
TajMahal
string_programs_in_c.htm
Advertisements
To Continue Learning Please Login
Login with Google