C Examples

WAP in C to concatenate two strings in a third string inputted by user

The Program in C to concatenate two strings in a third string inputted by user is given below:

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

int main() {
    char str1[100], str2[100], str3[200];

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

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

    strcpy(str3, str1); //copying str1 to str3
    strcat(str3, str2); //concatenating str2 to str3

    printf("The concatenated string is: %s", str3);

    return 0;
}

Output:

Enter the first string: hello
Enter the second string: codeauri
The concatenated string is: hellocodeauri

Pro-Tips💡

This program first declares three character arrays (strings) of size 100, 200 and 100 for storing the input strings and the concatenated string respectively.

Then it uses the scanf() function to prompt the user to enter the first and second strings, which are stored in the str1 and str2 arrays.

The strcpy() function is then used to copy the contents of str1 into str3, and the strcat() function is used to concatenate the contents of str2 to the end of str3.

Finally, the program uses the printf() function to print out the concatenated string stored in str3.

Learn C-Sharp ↗

C-sharp covers every topic to learn about C-Sharp thoroughly.

Learn C Programming ↗

C-Programming covers every topic to learn about C-Sharp thoroughly.

Learn C++ Programming↗

C++ covers every topic to learn about C-Sharp thoroughly.

Codeauri is Code Learning Hub and Community for every Coder to learn Coding by navigating Structurally from Basic Programming to Front-End Development, Back-End Development to Database, and many more.

Related Posts

C# Program to Find Sum of Rows & Columns of a Matrix

The Program in C# Program to Find Sum of Rows & Columns of a Matrix is given below: Output: Hello Codeauri Family,enter the number of rows and columns…

C# Program to Calculate Determinant of Given Matrix

The Program in C# Program to Calculate Determinant of Given Matrix is given below: Output: Hello Codeauri Family, enter the number of rows and columns of the matrix…

C# Program to Find Sum of right Diagonals of a Matrix

The Program in C# Program to Find Sum of right Diagonals of a Matrix is given below: Output: Hello Codeauri Family, enter the number of rows and columns…

C# Program to Find Transpose of Given Matrix

The Program in C# Program to Find Transpose of Given Matrix is given below: Output: Hello Codeauri Family, enter the number of rows and columns in the matrix:22Enter…

C# Program for Multiplication of two square Matrices

The Program in C# Program for Multiplication of two square Matrices is given below: Output: Hello Codeauri Family, enter the number of rows/columns in the matrices:2Enter the elements…

C# Program to Delete Element at Desired position From Array

The Program in C# Program to Delete Element at Desired position From Array is given below: Output: Hello Codeauri Family, enter the number of elements in the array:4Enter…

Leave a Reply

Your email address will not be published. Required fields are marked *

Your Journey into Code Begins Now: Discover the Wonders of Basic Programming

X