Hi.
How can I use this above, all set globally, to fill people with different "person"s? I am having issues wrapping my head regarding the typedef struct pointer.
I am aware pointers are like arrays, but I'm having issues getting this all together...

If you're "aware that pointers are like arrays", it would be best to empty your mind, throw away your book and start over with a better one.
–
Kerrek SBSep 9 '12 at 2:32

3

I personally don't like hiding the pointer type inside the typedef like that. In your case, it also appears to be wrong. Can you change those definitions at all?
–
Carl NorumSep 9 '12 at 2:38

Pointers and arrays while related... are not the same thing.
–
AndrewSep 9 '12 at 3:31

When you say "all set globally" do you mean that you want a massive code block that will initialize a big block of these to a set of known values. As in you don't want to add to the list of people during runtime, but set it up completely before?
–
Jon LSep 9 '12 at 4:48

Well the code above is global. I will have functions such ass "addPerson()", etc. Sorry for confusion.
–
AbhishekJoshiSep 9 '12 at 4:54

I don't think this answer is right, given the OP's definitions of person and people.
–
Carl NorumSep 9 '12 at 2:44

That was my error. It was meant to be a char*. Testing the above code now.
–
AbhishekJoshiSep 9 '12 at 2:49

@JonathanLeffler, yes, I just assumed that it was a typo in the question.
–
Deepanjan MazumdarSep 9 '12 at 2:49

3

sizeof(person) is still going to be the size of a pointer, not the size of a structure, though. Anyway, since person is a pointer type, I think there needs to be some more allocation here.
–
Carl NorumSep 9 '12 at 2:51

@CarlNorum, yes you are right, had not noticed that!.. actually then people becomes a double pointer.. not sure of the motive here.
–
Deepanjan MazumdarSep 9 '12 at 2:54

I think the OP is not aware of the double pointer implied. (that being that the typedef embeds one and then the allocation creates another one). Might want to explain that a little more.
–
Jon LSep 9 '12 at 4:46

Thanks for replies. @Carl, if you can explain a tad more, I would highly appreciate it! Basically double vs single.
–
AbhishekJoshiSep 9 '12 at 4:56

@AbhishekJoshi - your typedef has a * in it, which means the type you're creating is a pointer type. Then you declared a global variable of type person *, but since person is already a pointer type, you end up with a global variable that is a pointer-to-a-pointer-to-your-structure. Just delete the * on line 6 of your example to clean things up.
–
Carl NorumSep 9 '12 at 6:05