To use your struct like you are attempting you need to define it as follows:
typedef struct _CODE_POSTAL
{
UInt32 dwCode;
Char szCommune[25];
UInt8 iIndex;
}CODE_POSTAL;
Note: You should not assign a value to szCommune > 24 characters in length.
If you do you may not generate an error but you will be writing over memory
outside of your structure.
A more memory efficent way of doing this would be:
typedef struct _CODE_POSTAL
{
UInt32 dwCode;
Char *szCommune;
UInt8 iIndex;
}CODE_POSTAL;
CODE_POSTAL PostalList[10];
PostalList[0].dwCode = 9420;
PostalList[0].szCommune = MemPtrNew(StrLen("Aaigem")+1);
StrCopy(PostalList[0].szCommune, "Aaigem");
PostalList[1].dwCode = 9420;
PostalList[1].szCommune = MemPtrNew(StrLen("Aalbeke")+1);
StrCopy(PostalList[1].szCommune, "Aalbeke");
PostalList[1].dwCode = 9420;
PostalList[1].szCommune = MemPtrNew(StrLen("Aalst")+1);
StrCopy(PostalList[1].szCommune, "Aalst");
...
If you do it this way you need to free the memory you allocated with
MemPtrNew once you are done with it:
MemPtrFree(PostalList[0].szCommune);
MemPtrFree(PostalList[1].szCommune);
MemPtrFree(PostalList[2].szCommune);
...
If you are new to C programming I highly suggest getting a good C
programming How To book, don't get a C++ book. Although you can use C++ on
the Palm most of what you will do should conform to C programming standards.
Richard
----- Original Message -----
From: "Durieux Jean-Marc" <[EMAIL PROTECTED]>
To: "Palm Developer Forum" <[EMAIL PROTECTED]>
Sent: Sunday, October 07, 2001 10:05 AM
Subject: Struct Table
> Hi,
>
> This is certainly a stupid question but I have a problem when I define a
> struct table.
>
> This is the definition of my struct :
>
> typedef struct _CODE_POSTAL
> {
> UInt32 dwCode;
> Char *szCommune;
> UInt8 iIndex;
> }CODE_POSTAL, *PCODE_POSTAL;
>
> And this is the declaration of my table :
>
> CODE_POSTAL CodesPostaux[TAB_COMMONS]=
> {
> {9420 ,"Aaigem"},
> {8511 ,"Aalbeke"},
> {9300 ,"Aalst"},
> {3800 ,"Aalst"},
> {9880 ,"Aalter"},
> {3200 ,"Aarschot"},
> {8700 ,"Aarsele"},
> {8211 ,"Aartrijke"},
> {2630 ,"Aartselaar"},
> {4557 ,"Ab�e"}
> };
>
> But when I try to load a value in the table (CodesPostaux[i].szCmmune, for
> exemple), I've an error ...
>
> Could someone help me ?
>
> Jean-Marc
>
>
> --
> For information on using the Palm Developer Forums, or to unsubscribe,
please see http://www.palmos.com/dev/tech/support/forums/
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/tech/support/forums/