From: "J�lio F�bio de O. Chagas" 
> What is wrong with the code bellow ?
>
> typedef struct {
> Char * formName;
> } myFormStruct;
> typedef myFormStruct *myFormStructPtr;
> ...
> void myFunction()
> {
>  myFormStructPtr myform;
>  Char *buffer;
>  myform = (myFormStructPtr) MemPtrNew(sizeof
>     (myFormStruct ));
>  buffer = "FormNumberOne";
>  StrCopy(myform->formName, buffer);
>  ...
> }
>

You have not allocated any space to store the 14 chars
of "FormNumberOne" in myform->formName.  

sizeof(myFormStruct) is likely to be 4 bytes -- it
contains a single pointer to Char.  It does not
contain any space to store a string.

Try code like this (untested, OTTOMH*):

  // I assume buffer is just to illustrate.
  // Otherwise, why not just copy the string
  // directly to formName?
  Char *buffer;
  buffer = "FormNumberOne";
  ...
  // get memory for formName and copy buffer to it
  Char *formName;
  formName = (Char *) MemPtrNew(StrLen(buffer)+1);
  StrCopy(formName, buffer);

*OTTOMH == Off The Top Of My Head :)


__________________________________________________
Do You Yahoo!?
Yahoo! GeoCities - quick and easy web site hosting, just $8.95/month.
http://geocities.yahoo.com/ps/info1

-- 
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