In: Computer Science
Write a program that prompts the user to input their first name from the keyboard and stores them in the variable "firstName". It does the same for last name and stores it in the variable "lastName". It then uses strcat to merge the two names, separates them by a space and stores the full name into a string variable called "fullName". In the end, the program must print out the string stored within fullName. ANSWER IN C LANGUAGE !
You may use the following declarations for this problem:
char firstName [50];
char lastName [50];
char fullName [50];
You *must* use the function below to print out the full
name:
void printName(char fullName[])
Changing the function or its parameters is not permitted.
======================
Sample Output:
======================
Please enter your first name: John
Please enter your last name: Wick
Your full name is John Wick
#include<stdio.h>
void printName(char fullName[])
{
printf("\nFull Name is : %s",fullName);
}
int main()
{
char firstName[50];
char lastName[50];
char fullName[50];
int c1,c2,c3,i;
c1=c2=c3=0;
printf("\nEnter first name :");
scanf("%s",&firstName);
printf("\nEnter last name :");
scanf("%s",&lastName);
while(firstName[c1]!='\0')
c1++;
while(lastName[c2]!='\0')
c2++;
while(c3<c1)
{
fullName[c3]=firstName[c3];
c3++;
}
fullName[c3]=' ';
c3++;
i=0;
while(i<c2)
{
fullName[c3]=lastName[i];
i++;
c3++;
}
fullName[c3]='\0';
printName(fullName);
}
If you have any doubt comment down and get it cleared.. Also please upvote if you are satisfied with answer...