A structure person is defined in a program. An array of pointer to person, p is created for me to store up to 10 persons using DYNAMIC MEMORY.
I need to do the following tasks in the main():
1) Read person information in file (person.txt) and store to array p using DYNAMIC MEMORY. Set the spouse pointer for each person to NULL value first.
2) Perform marry operation for Mary and Tom. You can marry two person by setting their spouse pointer to point to each other (store address of one another). You need to go through the array to find Mary and Tom by comparing name using strcmp.
3) Print out the content in array p where you need to print every person variable pointed by array p. If a person spouse pointer is NULL value, then print “Not Married”, else print the spouse name. Output of the program is shown in below. Make sure your output is exactly the same.
1) Look through the array to find Mary, and when you do, get and hold onto a pointer to Mary.
2) Look through the array to find Tom, and when you do, get and hold onto a pointer to Tom.
3) Look through the array to find Mary, and when you do, set her spouse pointer to be the same as the pointer you got in step 2.
4) Look through the array to find Tom, and when you do, set his spouse pointer to be the same as the pointer you got in step 1.
while the exercise is about pointers, so you need to do what it says, if you have an array, the index is effectively a pointer. if you determine that array[25] == 'mary' then 25 is just as good as pointer= &(array[25]) for practical applications, and a bit easier to manage.
Just something to keep in the back of your mind. I dislike exercises that force students to do things that don't make any sense. It looks like they want pointers (in some places not all) where it isnt necessary.
Because programmer35 is very inexperienced and thinking about things in this kind of logical, programmatic way is very new, so I wrote the steps to be as simple and similar as possible.
If programmer35 can improve the method to do it more efficiently, good for programmer35.