Final answer:
The program in C requires the creation of two functions, getName and displayName. getName fetches and concatenates the first and last names, while displayName prints out the full name and its length using the strlen function.
Step-by-step explanation:
The question involves writing a program in C to concatenate two strings representing a user's first name and last name to form a full name. The program must include a function named getName to prompt the user and get their first and last names separately, concatenate them with a space between them, and finally a function named displayName to display the resulting full name along with its length.
Here is a sample code that follows the given requirements:
#include
#include
void getName(void);
void displayName(char *fullname);
int main() {
getName();
return 0;
}
void getName(void) {
char firstName[50], lastName[50];
char fullName[100];
printf("Enter your first name: ");
scanf("%49s", firstName);
printf("Enter your last name: ");
scanf("%49s", lastName);
strcpy(fullName, firstName);
strcat(fullName, " ");
strcat(fullName, lastName);
displayName(fullName);
}
void displayName(char *fullname) {
printf("Full Name: %s\\", fullname);
printf("Length of Full Name: %zu\\", strlen(fullname));
}
This code is designed to handle names up to 49 characters long. The strlen function is used to calculate the length of the concatenated full name, while the strcat function is responsible for appending the last name to the first.