Lauren,

I think that there are confusions between variables and pointers in your
mind

char Name[10];    => a space of ten characters has been reserved for
variable Name ready to be used
                        ex : StrCopy ( Name, "PalmOS" );

char *Name;            => here, Name is a pointer which points to somewhere in
the memory, you cannot use it
                        You have to allocate a memory area first. When it is done, 
Name will
"contain" the address
                        of the memory area allocated. Now you can use it.

So if you have,

struct _StudentRecordA {
        Int32   ID;
        char    Name[10];
};


struct _StudentRecordB {
        Int32   ID;
        char    *Name;
};


and you store _StudentRecordA in your database, the ID and the Name will be
stored.

But, if you try to store  _StudentRecordB, only the ID and the "ADDRESS of
the memory allocated"
which will be stored since the memory area will allocated outside of the
structure.

The best way, and the easiest is to fix the size of your variables you want
to use as a table like in
_StudentRecordA. Don't forget to add one extra space for the '\0' string
terminator...

You can find more informations about pointers in a great book written by
Kernighan and Ritchie
"le langage C" ( I guess that you are fench ). It's a reference in C
programming.


Cordialement/Greeting,
Agus Silas
********************************************
********************************************

-----Message d'origine-----
De : [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]]De la part de Lauren
B. Robert
Envoy� : mercredi 25 septembre 2002 13:14
� : Palm Developer Forum
Objet : Re:Struct problem or maybe other problems...


Hi All, I had changed the codes in my program. Although I can compile
successfully, when I debug on POSE, I had to do a reset whenever I tap on
the dynamic list. After setting a few breakpoints below, I noticed the
variable (*rec) "contains" garbage. I step-over the breakpoint, but at
MemHandleUnlock, I had to do a reset.

typedef struct {
    Int32 ID;
    const char *Class;
    const char *Name;
    const char *Gender;
 } StudentRecord;

//Dynamic List Function
for (indx=0; indx < NumRecor; indx++)
{

  RecordHa = DmQueryRecord(name, indx);
  rec = (StudentRecord *) MemHandleLock(RecordHa);//breakpoint
  RecordPointr = rec->Name + StrLen(rec->Name) + 1;
  MemHandleUnlock(RecordHa);//breakpoint
}

I managed to find similar problems like this in the archives, but none of
them provide a solution to it. One of them mention: "Your structure does
not contain any space to store a string.  "Char *Name " only declares a
pointer to Char.  You have to allocate space somewhere to store the string,
and assign the address of that string to Name(in this case).  Also, when you
write your structure to the database, you will be saving the pointer, not
the string of characters." But this only adds more question marks above my
head, can someone understand this or tell me what did I did wrong?


Many Thanks
Regards,
Lauren


____________________________________________________________
Tired of all the SPAM in your inbox? Switch to LYCOS MAIL PLUS
http://www.mail.lycos.com/brandPage.shtml?pageId=plus

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


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

Reply via email to