--- siddharth saxena <[EMAIL PROTECTED]> wrote:
> 
> FileWrite(streamsave,textp,sizeof(textp),1,NULL);
> this statement requires the size of the text to be
> saved. i can easily get the size of the text to be
> saved in UInt16 datatype. 

Then why didn't you do that in your code?

> but here i need to specify it in Int32 terms.
> typecasting obviously is not the solution.

Why not?  You can easily typecast a UInt16 to an Int32 without losing
any information.  (However, you can't do it the other way, 32->16,
without possibly losing data.)

> how should i specify the size.

As the number of bytes in the string that you are trying to write (plus
1 for the null terminator.)

> besides i tried saving just a single character . that
> also gave the same problemi.e."ADDRESS ERROR" &"BUS
> ERROR".

Which is probably because you didn't properly initialize some
pointer...

> pls reply.

Here is your original code, along with more comments:

  Err *errp;
  Char *textp;
  FieldType *fldp;
  UInt16 objindex,len;
  FileHand streamsave;
  FormType *frmp;

  frmp=FrmGetFormPtr(1000); //1000 is my form's ID
  objindex=FrmGetObjectIndex(frmp,1004);//1004is field ID
  fldp=FrmGetObjectPtr(frmp,objindex);
  textp=FldGetTextPtr(fldp);
  len=FldGetTextLength(fldp);

len is the length of the text you want to write, so just add 1 to it
(for the null) and write that many bytes to your file stream.

 
streamsave=FileOpen(0,filename,filetype,filecreator,fileModeUpdate,errp);

You are passing errp to FileOpen which expects to use it to return an
error code.  But you didn't allocate space for the return code, you
just created the pointer.  What you should have done is:

  Err err;
  // ...
  streamsave = FileOpen(..., &err);

Back to your code:

  ErrAlert(*errp);
  FileWrite(streamsave,textp,sizeof(textp),1,NULL);

Here you are telling FileWrite to write 4 bytes of data, starting at
the location that textp points to.  Instead, you should be telling it
to write len+1 bytes.  NOTE: sizeof(pointerToString) does not give you
the length of a string.  You have to use StrLen(pointerToString) and,
if you want to include the null at the end of the string, add 1 to
that.

  FileClose(streamsave);

Try making those changes and see if it works.


__________________________________________________
Do You Yahoo!?
Yahoo! Greetings - send holiday greetings for Easter, Passover
http://greetings.yahoo.com/

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

Reply via email to