I have a struct like so
typedef struct person {
int id;
char name[20];
} Person;
Then, outside of the function, I have a pointer array of pointers to these structs, like so
Person **people;
Then in the function I am adding people to the array like so (in a loop)
Person person;
for (i = 0; i < 50; i++)
{
person.id = i;
person.name = nameArray[i];
people[i] = &person;
}
person is being added to the people array but when (in VS2010) I go to the Watch screen and type people, 50
I just see the same person in every slot as if when adding the next person, it changes all previous as well. What am I doing wrong here?
Also, to retrieve a certain person's name, is this the right syntax?
people[0] -> name; Or is it people[0][0].name?
Thanks!
char[20]to all'\0'before callingfscanf. Afterfscanfreturns, dofor(int i=19;i>=0; i--) {if(s[i]=='\0') s[i]=' '; else break;}.