Answered step by step
Verified Expert Solution
Question
1 Approved Answer
The user will input ten pairs of C-style null-terminated strings about movies. The first string will contain the name of the genre. The second string
- The user will input ten pairs of C-style null-terminated strings about movies. The first string will contain the name of the genre. The second string will contain the title of the song
- As always, prompt the user before getting the input.
- Assume the input string will be less than 30 characters long.
Programming Requirements
- Define a struct called SongInfo that has two fields:
- a pointer to a string for the genre
- a pointer to a string for the title
- Both pointers must be set up by using malloc() once you know how long each string is (failing to use malloc will result in a mark of 0). Dont forget to add one to the length for the null-termination.
- Define the SongInfo struct before any of your functions. This does not violate the banning of global variables since these are data types, not variables.
- In main(), declare an array variable of struct SongInfo of size 10.
- Write a function called geSongInfo that takes a pointer to a struct Songnfo (which is a pointer to an element of the array) and the two movie information strings containing the genre and title information as parameters and fills in the struct's fields. Note the data type of the first parameter. You are taking in a pointer to a struct, not an array and not a struct. This function is also where you will allocate the two blocks of memory to contain the genre string and title string.
- Write a function called printSongInfo that takes the array of structs as a parameter and prints all of the information contained within the array in a nicely-formatted fashion, one song per line. The genre must be displayed in the first 35 characters of the line (left-justified) and the title must be displayed in the next 35 characters of the line (left-justified). You must use printf() width specifiers (or research how to specify widths using cout) to help with your formatting.
- Note that getSongInfo must be called once for each movie (genre/title pair) while printSongInfo must be called only once in total. You will likely want to call them from main().
- You must free the memory allocated once you are done.
- Do not use calloc(). Do not use the C++ new operator. Do not use the C++ string class objects (since they won't work properly with malloc()).
- Do not have any other input or output.
This is done is C programming
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started