Question: You are again going to write your own main function so the program runs. Create a program that reads all the superhero information from a

You are again going to write your own main function so the program runs. Create a program that reads all the superhero information from a file and provide an interface for the user to query superhero entries. Your program must support the following functionalities as options: * Option 1: to load a data file - ask the user to input the name of the file containing superhero information and load the entries from that file (report # of entries). Note that the file can be non existent (if so the program should print the error and keep running), but if it exists you can assume the format inside that file is valid and consistent, with each line having at most 300 characters. It is possible for the user to load a different file by choosing this option again, which will replace the previously loaded entries. You can assume the filename has at most 50 characters and no space. * Option 2: to list entries sorted by height - list the superheroes from shortest to tallest. Within entries with the same height (if exist), they should be ordered by name (as determined by strcmp).* Option 3: to list entries sorted by name - list the superheroes sorted by name (as determined by strcmp). Within entries with the same name (if exist), they should be ordered by height. * Option 4: to lookup a superhero - ask the user for a superpower for at most 50 characters (space included), then report all entries with superpower having the input as a substring. There can be more than one entry. The lookup is case-sensitive (i.e.,fly and Fly are not the same). o If one or more entries are found, print all the information. Any order is acceptable. o If no entry is found, print No such superhero on record. You can assume the user will always enter at most 50 characters. * Option 5: to terminate the program - thank the user and end the program. Your program must meet these requirements: * Include the provided header file (.h file) and use the functions defined in the corresponding implementation file (.c file) in your driver file (where main is), do not redefine those functions. * Use a dynamic array of Superhero struct pointers to store the superhero information. This is the recommended approach from A2(instead of a static array with a fixed size) as we might change the number of entries in the provided file, and dynamic arrays can accommodate that variation. * There must be no memory leaks (e.g., your program requests some memory but does not release them all before it terminates). In CSIL you can use the Valgrind tool as described to check for that. * Start with a fancy banner. There is no specific requirement besides it must include your name, 9 digit SFU ID, and your SFU email address. Let your creativity shine, just nothing offensive. * If a functionality (e.g., list, lookup) is requested by the user but no file has been loaded, the program should print an error message telling the user that no file have been loaded and prompt the user to do so (e.g.,No superheroes file loaded. Load one first.).* The sorting for Options 2&3 can be done using any sorting algorithms covered in class, including the built-in qsort, which requires to you to write your own compare functions. See a3_(s)uperherolib.h for details. And here are some hints for you to write your code: * The program interface is essentially a do-while loop where in each iteration it asks for an option and determines what to do, with a repeating conditional of the terminating option has not been inputted. It is a common approach for menu-based interfaces. * Since each item in the dynamic array for the superhero entries are pointers, be careful with how you are casting the pointer variables in the compare functions for qsort (they are pointers to the items)- suppose the dynamic array has the type A**, then the variables should be cast to A**.* The scanf() function works slightly differently between different formats. One difference is how it handles leading and trailing newlines (look up dangling newline character if you are curious). One option to get around this is put a space in front of the format string (e.g.,%d,%s). You are encouraged to explore different ways to get around this issue. *The entries are randomly generated using ChatGPT with a specific format and then lightly modified. Hence, the content might not make sense and have very similar wording patterns - no need to worry. Include the function definitions corresponding to a3_(s)uperherolib.h (and your helper functions, if any) in a source file named as a3_(s)uperherolib.c. Remember the .h file only contains the function headers.
write in C.

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 Programming Questions!