Advertisement

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

#include<stdio.h>
#include<string.h>

int main() {
    char str1[100], str2[100];
    int i = 0, j = 0;

    printf("Enter First String :");
    scanf("%[^\n]%*c", str1); 

    printf("Enter Second String :");
    scanf("%[^\n]%*c", str2); 

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

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

    return 0;
}

Output:

Enter First String :Xiith
Enter Second String :.com
Concatenated String: Xiith.com