CHAR *fnBufferDec(
signed long slNumberToConvert,
unsigned char ucStyle,
CHAR *ptrBuf);
slNumberToConvert is a signed long value to be converted to an ASCII decimal string in the output buffer pointed to by
ptrBuf.
The conversion style is defined by
ucStyle, which can be a mixture of following flags:
- DISPLAY_NEGATIVE - slNumberToConvert is handled as a signed number and displayed negative if appropriate
- LEADING_ZERO - the output string starts with a zero, which is useful when displaying time formats (eg. 12:04:07 in stead of 12:4:7)
- LEADING_SPACE - ensure display of time with 2 digits - space as filler
- WITH_SPACE - the output string starts with a space
- WITH_TERMINATOR (default)
- NO_TERMINATOR - the resulting string is without a NULL-terminator
- WITH_CR_LF - '\r\n' is added at the end of the string
The function returns a pointer to the last character in the buffer (generally the NULL-terminator). This pointer allows simple
concatenation since following string fragments can be added using this pointer.
Examples
CHAR buf[50];
CHAR *ptrBuf = buf;
ptrBuf = fnBufferDec(-125000, (DISPLAY_NEGATIVE), ptrBuf);
ptrBuf = fnBufferDec(125000, (LEADING_SPACE | WITH_CR_LF), ptrBuf);
Result in
buf[50] = "-125000 125000\r\n"
Example of formating time output
extern CHAR *fnUpTime(CHAR *cValue)
{
unsigned long ulUpTimeSecs = (uTaskerSystemTick / SEC);
unsigned long ulUpTime = ulUpTimeSecs /60/60/24; // the up time in days
CHAR *cPtr;
cPtr = fnBufferDec(ulUpTime, 0, cValue);
*cPtr++ = ' ';
*cPtr++ = 'D';
*cPtr++ = 'a';
*cPtr++ = 'y';
*cPtr++ = 's';
*cPtr++ = ' ';
ulUpTimeSecs -= (ulUpTime * 60*60*24); // minus the days
ulUpTime = (ulUpTimeSecs / (60*60)); // the UP time in hours
cPtr = fnBufferDec(ulUpTime, 0, cPtr);
*cPtr++ = ':';
ulUpTimeSecs -= (ulUpTime * 60*60); // minus the hours
ulUpTime = (ulUpTimeSecs / (60)); // the UP time in minutes
cPtr = fnBufferDec(ulUpTime, LEADING_ZERO, cPtr);
*cPtr++ = ':';
ulUpTimeSecs -= (ulUpTime * 60); // minus the minutes
cPtr = fnBufferDec(ulUpTimeSecs, LEADING_ZERO, cPtr);
return cPtr;
}
Related functions
fnDebugDec();
fnBufferHex();
fnHexStrHex();
fnDecStrHex();
Please use the
µTasker forum to ask specific questions.