<[EMAIL PROTECTED]> wrote
>
> Most of you out there will think this is a dumb question, but it's
> confusing......If I have a variable of type char, and I want to set it
with a
> variable and a string (i.e.-i want it to be equal to another char and
append
> a string to it, like a variable number of days and the string " days"). I
> hope this even makes any sense, because im totally stumped.
>
Try:
{
#define TEMPSTRSIZE 64
char TempStr[TEMPSTRSIZE];
UInt16 n;
n = 28;
StrIToA(TempStr, n);
StrNCat(TempStr, " days", sizeof(TempStr));
// For 'You have 28 days remaining.' you can use
StrNCopy(TempStr, "You have ", sizeof(TempStr));
StrIToA(&TempStr[StrLen(TempStr)], n); // not overrun-safe
StrNCat(TempStr, " days remaining.", sizeof(TempStr));
// The '&TempStr[StrLen(TempStr)]' isn't very efficient but
// is fine for building up strings on the fly.
// For commercial apps you should also consider storing
// your strings as resources so that translation to another
// langauge is easier. This takes a little time to set up
// but saves a lot of pain later on.
// alternatively you can use the TEMPSTRSIZE constant.
// In theory they're the same because sizeof() should
// be resolvable at compile time but I've never checked
// to see if CodeWarrior does this.
StrNCopy(TempStr, "You have ", TEMPSTRSIZE);
StrIToA(&TempStr[StrLen(TempStr)], n);
StrNCat(TempStr, " days", TEMPSTRSIZE);
}
I've used the StrN~ operators rather than the Str~ because they
protect against buffer over-runs which can Produce some particularly
nasty bugs (nasty = intermittent crashes and corruption side-effects)
Of course this might lead to a discussion on coding style :-)
Chris Tutty
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/tech/support/forums/