Question
1. In the main() function of lab7.c declare and define a 7 element array of string pointers (char *) called names. Initialize/Add each of the
1. In the main() function of lab7.c declare and define a 7 element array of string pointers (char *) called names. Initialize/Add each of the following 7 strings to the array of names. Note that two of the strings are empty and have a length of zero.
2. Write a for-loop to display all the strings in names. Include the empty strings that do not contain a name. The print line for each array element must include the following information.
Subscript value
Array row element memory address in hexadecimal
Address of the row element string in hexadecimal
Length of the name string in bytes
The name string characters Use this format template:
names [0] element addr 28FF18 string addr 40A064 contents 5 bytes Chris
names [1] element addr 28FF1C string addr 40A06A contents 4 bytes Lois
names [2] element addr 28FF20 string addr 40A06F contents 3 bytes Meg
names [3] element addr 28FF24 string addr 40A073 contents 0 bytes
names [4] element addr 28FF28 string addr 40A073 contents 0 bytes
names [5] element addr 28FF2C string addr 40A074 contents 5 bytes Peter
names [6] element addr 28FF30 string addr 40A07A contents 6 bytes Stewie
Once this loop is correct, add the following function prototype to your program, implement the prototyped function with parameter names, and move the for-loop to this function. You will have to call this function to print your array.
prt_names_array(char**, int); /* prototype */
prt_names_array(names, SIZE); /* function call */
3. Add "Brian" so that it is the 4th name in the array. Now add "Meg" to the third position in the array (there will be two identical strings "Meg" in the array).
4. Call your print function to display all the strings in names.
Chris
Lois
Meg
Meg
Brian
Peter
Stewie
5. Write a for-loop to remove "Meg" and display the revised array of names.
6. In the comments text box in the Blackboard assignment link answer the following question: were both instances of "Meg" removed from the list? If so why or if not why. This may require thought and reflection.
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