From: "Sebastian from Berlin/Germany" <[EMAIL PROTECTED]>
> i want to format a integer output to 4 digits. ("Card 0001","Card 0002"
...)
> i tried this one .. but i doesn't work ....
>
> StrPrintF(NewCard.title,"Card %4d",number);
>
The format specifiers for printf can vary from one compiler to
another and PalmOS only supports a subset. I didn't see a reference
to the zero-padding option in a quick browse of the PalmOS docs
but that doesn't mean it doesn't exist - I'd find a reference for
printf, find out what the zero padding option is and try that with
StrPrintF.
If that doesn't work there's always using StrIToA, then StrLen to
find out how long the number is, fill a work buffer with '0's
using MemSet (or keep a constant), terminate it at
MaxLen - length and StrCat the StrIToA result.
That's a general purpose solution and for only four bytes there
are faster ways to do it, also if you want an internationalised
solution you'll need to use the Txt~ functions rather than a
byte array.
It's a bit messy, but hide it in a function and you'll never have
to write it again. I'm still using the string formatting code I
wrote under DOS a zillion years ago.
Chris Tutty
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/support/forums/