String concatenation means joining two or more strings together to create a single string. In C language, the strcat() function is used to combine two strings, and the strcpy() function is used to copy one string into another.
In this program, the user enters the first name and last name separately. The program combines both strings using strcat() and stores the final full name using strcpy().
How It Works?
Lname, Fname, and full to store strings.strcat().strcat().full variable using strcpy().#include <stdio.h> #include <conio.h> #include <string.h> main() { char Lname[20], Fname[20], full[20]; clrscr(); printf("Enter the Last Name : "); scanf("%s", Lname); printf("\nEnter the First Name : "); scanf("%s", Fname); strcat(Fname, " "); strcat(Fname, Lname); strcpy(full, Fname); printf("\nFull Name Is %s", full); getch(); }
strcat() function. Display the final combined string.strcat() to join the second string with the first string and display the final concatenated string.#include <stdio.h> #include <conio.h> #include <string.h> main() { char first[20], second[20]; clrscr(); printf("Enter First String : "); scanf("%s", first); printf("\nEnter Second String : "); scanf("%s", second); strcat(first, second); printf("\nCombined String Is %s", first); getch(); }
strcat() function. The second string is added at the end of the first string, and the final combined string is displayed.