The program

This program is an exercise in using linked lists. The user will enter a number of strings and the program will display the list in alphabetical order. Running the program may display:

enter a new name (y/n)? y
name: Eleanore Roosevelt
enter a new name (y/n)? z
bad input, try again
enter a new name (y/n)? y
name: Jack the Ripper
enter a new name (y/n)? y
name: Elvis Presley
enter a new name (y/n)? n

Eleanore Roosevelt
Elvis Presley
Jack the Ripper

Internals

Your program will accept all input using the fgets()) function to allow white space in the input. This function will be discussed in class. The program will accept names from the user and insert each name into a linked list. When a new name is entered into the list it is placed in a position which maintains the list in alphabetical order -- e.g. Mata Hari would be placed between John Lennon and Superman if those names were already in the list. When the user is done entering names the list will be traversed displaying the names in list (and hence alphabetical) order.

To determine when one name (string) precedes another in alphabetical order use the following function:

int strcmpi(char *s1, char *s2)
{
while (*s1 && tolower(*s1) == tolower(*s2))
{
s1++;
s2++;
}
return tolower(*s1) - tolower(*s2);
}

This function will return a negative value if s1 precedes s2, a positive value if s2 precedes s1 and 0 if they are equal.

As seen in the example above, the program will ask the user if he or she wants to enter a new name. The program will accept new names as long as the user enters "y". If the user enters anything other than "y" or "n" the program will continue to ask until the user enters a valid response. Responses to this prompt will also be accepted using fgets().

Your program must display good programming style (to be discussed in class) and make appropriate use of functions.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.