Question: Write a program that formats a user entered name (consiting of a first and last name) and then displays it in the format last name,

Write a program that formats a user entered name (consiting of a first and last name) and then displays it in the format last name, a comma, the first name initial, and a period. Your program should work as follows:

Enter the first and last name: James Smith

Formatted name: Smith, J.

Constraints:

Your program should use the following function to format the name:

void format_name (char *name);

The function takes as input the string entered by the user and then it modifies the string name to obey the formatting constraint indicated above.

Your program should use pointer arithmetic, not array subscripting, to process the string.

Modify the above program to work even if the user input includes extra spaces before the first name, between the first and last name, as well as after the last name. These spaces should not be printed in the formatted name.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!