I'm doing the addressbook by structures program(I'm sure many of you have seen it) and I'm stuck at the function where you search the global addressbook array for the right structure via a match from an string taken from the user. It always prints out a wall of jibberish and the first name here and there when I get to that portion of the program instead of just clearly printing out the info requested. What am I doing wrong here?
Side question: Part of the program involves using the getPerson function. I think I've done the function correctly but I'm wondering, what's the point of even having it? How do I implement it to main to be relevant?
In addition to the above answer, you should also move that "return false" to be the last statement executed in your code.
This leads to the next problem in your code. When you are adding people to the address book, you are using the same person struct to add people. So when you have finished adding people, you have every pointer in the address book pointing at the same person (The last person added).
Not sure you need both a getPerson and findPerson functions. Just use findPerson
Here is my updated code as well as he instruction of the getPerson function follow:
"In main create a person struct
call getPerson passing the created struct by reference
If the addressBook is empty getPerson simply returns false
If the addressBook is not empty the next person in the addressBook is copied to the struct passed by reference and true is returned
*If the last person in the address book is returned back then the next call to getPerson will get the first person again."