"Wang, Nancy" wrote:

> Hello,
>
>   I remember some previous posting about StrPrintF crashes. I met the same
> problem with the following code:
>
>   CharPtr strP = NULL;
>   Int16 hexval = 128;
>
>   StrPrintF(strP, "%02x", hexval);

Writing to a null string pointer will crash in almost any environment.  You need to 
allocate memory to the pointer for the
StrPrintF to put its results somewhere.  At this level, there is now allocation 
checking per system call due to memory and speed
restrictions.  A correction for the above would be.

char field[32];
CharPtr strP = field;
Int16 hexval = 128;

StrPrintF(strP, "%02x", hexval);

Also, the field length definer "02" will not work for %x in the current PalmOS 
implementation of StrPrintF.  You will always get an
eight character field.  To work with it further, you need to trim the field after 
calling StrPrintF.

Steve



-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palm.com/devzone/mailinglists.html

Reply via email to