Thursday, 25 August 2016

C Program to concat two strings without using strcat()


A simple C program which concats two strings. the second string appends to first string and forms a concatenated string.

Here string concatination is done without using strcat() function.

Look below for program and the screenshot,





Download code

PROGRAM : 

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

int main()
{
    char string1[50], string2[50];
    int i, j;
    printf("\nEnter First string :");
    gets(string1);
    printf("\nEnter Second string :");
    gets(string2);
    i = strlen(string1);
    for (j = 0; string2[j] != '\0'; i++, j++)
    {
        string1[i] = string2[j];
    }
    string1[i] = '\0';
    printf("\nConcatinated string is :%s\n", string1);
    return (0);
}
Download code

OUTPUT : 

C Program - String concatenation without strcat