PRINTF
 
Syntax

SUB PRINTF ("C format string", ParamArray ...)

built-in SUB that calls the existing printf routine in the firmware for versions 8.11 or later (version 7.51 or later on ARM7 parts)
Description


PRINTF is a way to format printed output.  It can be as simple a short string or quite complex specifying field sizes and pad characters for a number.  This routine is written in C and is part of the firmware.  As of 8.11 firmware BASIC programs can access this powerful C subroutine.

Rather than duplicate the documentation of PRINTF, there is a great deal of information for printf in documentation for C such as

C reference for printf

PRINTF in the firmware supports c (BYTE),  s (STRING),  d (decimal INTEGER),  x or X for (hex INTEGER), e, E,  f, g, or G (for SINGLE).

The G format is used by the ARMbasic PRINT, it differs a little from the G format of C.  It displays 0.0 or the range 0.1000000 through 9999999. and outside that it uses D.DDDDDDE+DD and the negative values as well.

Pad characters of 0 or space can be added to fill out LENGTH or WIDTH and PRECISION.  PRECISION is limited to 0 to 8 characters.

To add CR <carriage return> to the output printed, either use PRINT or print a %c with a value of 13

Example


PRINTF("a simple string")

i = 1234
PRINTF(" %d",i)                           ' print a decimal integer

DIM x AS SINGLE
x = 12.34
PRINTF(" %1.4f",x)                       ' print a floating point number with 4 digits of precision

PRINTF("%c%c a string a single %1.5f an integer %d a hex number %x and a carriage return %c",13,13,x,i,i,13)
will print out --

a simple string 1234 12.3400

a string a single 12.34000 an integer 1234 a hex number 4D2 and a carriage return

Differences from other BASICs

See also