In this tutorial, we are going to learn C program to Concatenate Two Strings without using strcat() (string concatenation in c)
This program is very simple we do not need any extra logic. Using basic string knowledge we can write this program. These type of program are asked in interviews or tests.
String: string is a collection of characters and string always ends with null character ‘ \0’.
The logic to concatenate string without strcat():
As we know string always ends with the null character. Using this point we concatenate a string.
Traverse first string till the end and after that copy second string in first string.
(Note: it is necessary to append null character at end of the string which indicates the ends of string)
2. Declare two strings.
3. Take user input two strings.
4. Traverse first string till the end (till null)
5. Append each character from second string to the first character till second string null character reaches.
6. Print first string (concatenated string)
C program to Concatenate Two Strings without using strcat()
char s1, s2, i, j;
printf("Enter first string: ");
printf("Enter second string: ");
// calculate the length of string s1
// and store it in i
for(i = 0; s1[i] != '\0'; ++i);
for(j = 0; s2[j] != '\0'; ++j, ++i)
s1[i] = s2[j];
s1[i] = '\0';
printf("concatenated string = : %s", s1);
1. First we declare the variable
str1 => for string 1
str2 => for string 2
i, j => for iterating
2. Take user input string1 and string2
Suppose user input
str1 = technical
str2 = seek
3. Next line is
This is to traverse first string till end
As str1 = technical\0
After this line str1[i] points to \0
And value of i = 10
4. Next line is
str1 [i] = ‘ ‘;
As we know str1 [i] = str1  = ‘\0’
We remove null character from str1 (as we appending second string) and put space at this position.
Next line is
After entering space in str1 we appending second string after space so we increment i value from where the second string starts.
Next lines are
for (j = 0; str2 [j] != ‘\0’ ; j++)
str1 [i] = str2 [j] ;
Now we read second string from start one by one character and copy it to first string. Till second string ends.
5. After copying string2 to string1 we append null character at the end to indicate the end of the string.
6. Print str1 (concatenated string)