Tutorials, Free Online Tutorials,It Challengers provides tutorials and interview questions of all technology like java tutorial, android, java frameworks, javascript, core java, sql, php, c language etc. for beginners and professionals.

Breaking

C Program to Concatenate Two Strings


Concatenate Two Strings Without Using strcat()


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

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

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

    // calculate the length of string s1
    // and store it in i
    for(i = 0; str1[i] != '\0'; ++i);

    for(j = 0; str2[j] != '\0'; ++j, ++i)
    {
        str1[i] = str2[j];
    }

    str1[i] = '\0';
    printf("After concatenation: %s", str1);

    return 0;
}

Output:-





No comments:

Post a Comment