On Tue, Feb 12, 2002 at 10:49:48PM +0800, Low Pui Kuen wrote:
> Hi everyone,
> 
> I have a problem of reading out the members of the STUDENT structure.
> All the members are char pointers. When I try to read out the member (Name), 
> I got memory access error.
> Can anyone tell me what have I missed out? Or what is the way to access the 
> members(seems like ptr->Name doesn't work; the Name is char pointer) Thanks 
> in advance.
> 
> 
> typedef struct Student
> {
> 
>    Char *StudentID;
>    Char *Name;
>    Char *Sex;
>    Char *Age;
>    Char *Email;
>    Char *Phone_HP;
>    Char *Phone_H;
> 
> }STUDENT;

The problem is not in the way you retrieve the fields, but in the way you store
them. You are storing pointers, and this is clearly wrong:  you have to store the
strings and not their addresses.
You can either use array of characters in the Student structure (arrays are not
pointers, remember ? :-), and store those, or you can pack your data structure in
a single string, by separating fields with a separator character. The latter
solutions saves space but it is more complex to implement.

Cheers,
Marco

-- 
========================================================================
Marco Pantaleoni                                  [EMAIL PROTECTED]
Padova, Italy                                              [EMAIL PROTECTED]
elastiC language developer                   http://www.elasticworld.org

-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/tech/support/forums/

Reply via email to