value of array of pointers to struct changes when exiting loop

38 Views Asked by At

phonebook is an array of pointers.

inside the handleMenu im allocating memory and pointing to structure where a first name is assigned to a struct that is pointed from phonebook[11].

enter image description here

as you can see in line 54, the name is assigned correctly and the program remembers it when exiting the handleMenu function, and i can access the details of the structure.

but after going down 1 line and ending the main while loop, the value suddenly changes.

enter image description here

what causes it and how to solve it? i want to remember the address to the structure but it seems that it wont save.

thanks in advance!

1

There are 1 best solutions below

0
On BEST ANSWER

check this first:while(option < 1 && 7 < option) this condition will never happen! be sure from this. when you trying to assign array of pointer type structs it should be allocated first .