Home / Programs / C Program Concatenate Two Strings Without Using strcat()
🚀 Programming Example

C Program Concatenate Two Strings Without Using strcat()

👁 957 Views
💻 Practical Program
📘 Step Learning
In this article, you'll learn to easily concatenate two strings without using standard library function strcat().

💻 Program Code

#include <stdio.h>
int main()
{
    char s1[100], s2[100], i, j;

    printf("Enter first string: ");
    scanf("%s", s1);

    printf("Enter second string: ");
    scanf("%s", s2);

    // 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("After concatenation: %s", s1);

    return 0;
}
                        

🖥 Program Output

Enter first string: lol
Enter second string: :)
After concatenation: lol:)
                            

📘 Explanation

You can concatenate two strings easily using standard library function strcat() but, this program concatenates two strings manually without using strcat() function.

📚 Learning Subject

Master Programming Through Practical Examples

Improve your coding logic, problem-solving skills and programming confidence by practicing real-world examples with explanations.

🎯 How to learn from this example

First understand the algorithm carefully. Then study the program line-by-line and compare it with the output. Finally, review the explanation section to strengthen your logic and programming understanding.

🔥 Practice suggestion

Rewrite the program without looking at the code. Modify values, conditions or logic and run it again. This helps improve confidence and strengthens coding skills much faster.