Project

General

Profile

Format Strings

Introduction

The Dooba SDK provides a generic callback-based implementation for printf-style format strings: cprintf.
Most developers will never directly use the generic cprintf implementation, but rather some methods that rely on it.

Understanding these formats is essential to using any method that relies on cprintf.

This page will present the available formats and some usage examples.

Available format modifiers

Below is a table presenting all format modifiers available for use.
Examples are presented using an imaginary "printf" method.

Modifier Description Example
%s NULL-Terminated String
printf("This is a string: %s", "foobar");
-> "This is a string: foobar"
%t Fixed-length String
printf("This string doesn't need to be NULL-terminated: %t", "foobar", 6);
-> "This string doesn't need to be NULL-terminated: foobar"
%i Integer (Decimal)
printf("This is a decimal number: %i", 42);
-> "This is a decimal number: 42"
%h Integer (Hexadecimal)
printf("This is a hex number: %h", 42);
-> "This is a hex number: 2a"
%b Integer (Binary)
printf("This is a binary number: %b", 42);
-> "This is a binary number: 101010"

Literal '%'

To include a literal '%' character within a format string, it needs to be escaped by prefixing it with a backslash ('\').

Example:

printf("Percentage: 100\%");