In this tutorial you will learn about the C Program to Concatenate Two Strings Using strcat and its application with practical example.
C Program to Concatenate Two Strings Using strcat
In this tutorial, we will learn to create a C program that will Concatenate Two Strings Using strcat in C programming.
Before starting with this tutorial we assume that you are best aware of the following C programming topics:
- Operators in C Programming.
- Basic Input and Output function in C Programming.
- Basic C programming.
- Using String functions of c language.
Concatenate Two Strings Using strcat
As we all know the String is a collection of character data types. In strings, only one variable is declared which can store multiple values. First will take the number of elements of string 1 from the user. Then will take the number of elements of string 2 from the user. Then will take the elements from the user for string 1 and as well as for string 2. And concatenate them using the strcat function.
With the help of this program, we can Concatenate Two Strings Using strcat
1. Declaring the variables for the program.
2. Taking the input number from the user.
3. Adding the given sting to second string.
4. Passing those variables to strcat loop.
5. Printing the result words.
Program to Concatenate Two Strings Using strcat:-
// C Program to concatenate
// two strings using strcat
// Getting the two Strings to be concatenated
// Declare new String variables
// to store the concatenated String
char string1, string2;
//Gettin string one from user
printf("Enter the first string \n");
//Gettin string two from user
printf("Enter the second string \n");
// Print the concatenated string
printf("String obtained on concatenation is %s\n",string1);
In the above program, we have first initialized the required variable.
- string1 = it will hold the string value.
- string2 = it will hold the string value.
Taking Input string 1 from the user.
Taking Input string 2 from the user.
Printing Output using the strcat function which is available in c language.