Question

Please create a program answering the following question in C PROGRAMMING.

CorrectFormation Create a program and locally declare in main fname and Iname and completeName. Ask the user for their first and last name. Put the values into fname and Iname. You will create a function that is called as followed oinNames( fname, Iname, completeName ); You will pass the first name array, the last name array, and the array that will contain the complete name. The function named joinNames should put the first and last names together in completeName. Make sure that the first and last names begin with capital letters, and that all others are lower case. Display the final combined name. Please enter your first name:chuck wagon Please enter your last name: The complete name is Chuck Wagon Process returned e (exe) execution time : 5.192 s Press any key to continue.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Program:

#include <stdio.h>

#include <string.h>

int main(void) {

char fname[100],lname[100],completename[100];

printf("Please enter your first name:");

scanf("%[^\n]s",fname);

printf("Please enter your last name:");

scanf("%[^\n]s",lname);

joinNames(fname,lname,completename);

return 0;

}

void joinNames(char f[],char l[],char c[])

{

  

int i;

strcat(f, l);

strcat(c, f);

for(i=0; c[i]!='\0'; i++)

{

//check first character is lowercase alphabet

if(i==0)

{

if((c[i]>='a' && c[i]<='z'))

c[i]=c[i]-32; //subtract 32 to make it capital

continue; //continue to the loop

}

if(c[i]==' ')//check space

{

//if space is found, check next character

++i;

//check next character is lowercase alphabet

if(c[i]>='a' && c[i]<='z')

{

c[i]=c[i]-32; //subtract 32 to make it capital

continue; //continue to the loop

}

}

else

{

//all other uppercase characters should be in lowercase

if(c[i]>='A' && c[i]<='Z')

c[i]=c[i]+32; //subtract 32 to make it small/lowercase

}

}

printf("The completename is: %s\n",c);

}

Add a comment
Know the answer?
Add Answer to:
Please create a program answering the following question in C PROGRAMMING. CorrectFormation Create a program and...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT