Am Montag, den 24.04.2006, 16:26 -0500 schrieb Luis Cordova:
> I am getting an error when I do directly StrCopy(array, debug)
of course, AArray[i].Name is just a pointer to some random memory.
> that is why I changed to the other way. However, you are right I
> should be doing this, the problem is that I cannot intialize an static
> Array of structs in the same way as using MemPtrNew, maybe you can but
> I am not sure because it is not working and it acts weird when I debug
> seeing values that does not correspond. Any hint on how to allocate
> memories for arrays of structs?
static struct AStruct *AArray = MemPtrNew(sizeof(struct AStruct) * 5)); // for
AArray[0-4]
if (AArray == 0)
-> error
If you want to initialize everything with zero, use MemSet.
> > StrCopy(debug,"initialized");
> > AArray[i].Name = debug; <-- Name does not get string
Should work with the above, but do not erase debug unless you don't need
AArray[i].Name anymore (it's just a copy of the pointer, not a copy of
the string!)
> > StrCopy(AArray[i].Name, fileName); <--- does not work!
AArray[i].Name = MemPtrNew( --- length of string + 1 --- );
StrCopy(AArray[i].Name, fileName);
P.S.: Don't forget to MemPtrFree any memory you allocate.
Daniel
--
For information on using the PalmSource Developer Forums, or to unsubscribe,
please see http://www.palmos.com/dev/support/forums/