String formatting

From Amiga Development Wiki
Jump to: navigation, search

RawDoFmt

Text formatting is similar to sprintf() but integer types default to 16-bit integers!

Type Description
b BSTR
c, lc Character
d, ld Decimal
u, lu Unsigned decimal
s String
x, lx Hexadecimal

RawDoFmt() has no support for floats.

Usage:

STATIC CONST ULONG StuffChar[] = { 0x16c04e75 };
ULONG array[] = { (ULONG)"Hello world!" };
TEXT buf[200];
 
RawDoFmt("Print: %s\n", &array, (void (*)(void))&StuffChar, buf);

NewRawDoFmt

NewRawDoFmt() replaces old RawDoFmt() with proper varargs interface. The output is not compatible with RawDoFmt(), for example, integers default to 32-bits and hexadecimal output is in lower case. In RawDoFmt() it is in upper case. Floats are supported.

Usage:

TEXT buf[200];
 
NewRawDoFmt("Print: %s\n", NULL, buf, "Hello world!");

SNPrintf

SNPrintf() provides localized string formatting and buffer length checking.

Usage:

TEXT buf[200];
 
SNPrintf(locale, "Print: %s\n", buf, sizeof(buf), "Hello world!");