Easy Tutorial
❮ C Function Strstr C Structures ❯

C Language Example - Concatenating Strings

C Language Examples

Using strcat() to concatenate two strings.

Example

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

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

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

    // Calculate the length of string s1
    for(i = 0; s1[i] != '\0'; ++i);

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

    s1[i] = '\0';
    printf("Concatenated: %s", s1);

    return 0;
}

Output:

Enter the first string: google
Enter the second string: tutorialpro
Concatenated: googletutorialpro

C Language Examples

❮ C Function Strstr C Structures ❯