C Program to concatenate two strings without using strcat function


In this program, You will learn how to concatenate two strings without using strcat function in c.


strcat(str1, str2);


Example: How to concatenate two strings without using strcat function in c

Run it Now
#include<stdio.h>
#include<string.h>

int main() {

    char str1[100], str2[100];
    int i = 0, j = 0;

    printf("Enter First String :");
    fgets(str1, 100, stdin);
    strtok(str1, "\n");

    printf("\nEnter Second String :");
    fgets(str2, 100, stdin);

    while (str1[i] != '\0') {
        i++;
    }

    while (str2[j] != '\0') {
        str1[i] = str2[j];
        j++;
        i++;
    }
    
    str1[i] = '\0';
    printf("\nConcatenate String is: %s", str1);

    return 0;
}

Output:

Enter First String :John
Enter Second String :Smith
Concatenate String is: JohnSmith