Strings can be combined together to create a complete sentence or information. In C language, the strcat() function is used to join multiple strings, and the strcpy() function is used to copy one string into another.
In this program, the user enters the city name, state name, and country name. These three strings are combined to form a complete address. The final address is converted into capital letters using the strupr() function and displayed.
How It Works?
city, state, country, and address.strcat() to join the city, state, and country strings.address variable using strcpy().strupr().#include <stdio.h> #include <conio.h> #include <string.h> main() { char city[20], state[20], country[20], address[60]; clrscr(); printf("Enter the City Name : "); scanf("%s", city); printf("\nEnter the State Name : "); scanf("%s", state); printf("\nEnter the Country Name : "); scanf("%s", country); strcat(city, " "); strcat(city, state); strcat(city, " "); strcat(city, country); strcpy(address, city); printf("\nAddress is %s", strupr(address)); getch(); }
strcat(), strcpy(), and strupr() functions to join and format strings.strcat() to combine strings and strcpy() to store the final address. Convert the address into capital letters using strupr().#include <stdio.h> #include <conio.h> #include <string.h> main() { char house[20], city[20], country[20], address[60]; clrscr(); printf("Enter House Name : "); scanf("%s", house); printf("\nEnter City Name : "); scanf("%s", city); printf("\nEnter Country Name : "); scanf("%s", country); strcat(house, " "); strcat(house, city); strcat(house, " "); strcat(house, country); strcpy(address, house); printf("\nAddress is %s", strupr(address)); getch(); }
strcat() function. The complete address is copied into another string using strcpy() and displayed in capital letters using strupr().