| printf | Function (tigcc.a)

stdio.h

void printf (const char *format, ...);

Sends formatted output to the screen.

printf is nearly full implementation of standard ANSI C printf function, which sends the formatted output to the screen in terminal (TTY) mode. In fact, it does the following:

- accepts a series of arguments;
- applies to each a format specifier contained in the format string pointed to by format;
- outputs the formatted data to the screen.

The printed text will wrap on the right end of the screen. Characters '\n' will be translated to "next line" (and this is the only control code which has a special implementation). The screen will scroll upwards when necessary (i.e. after printing a text in the last screen line). Note that all TI fonts are supported. Of course, printf will update current "print position" to a new one after the text is printed.
printf applies the first format specifier to the first argument after format, the second to the second, and so on. The format string, controls how printf will convert and format its arguments. There must be enough arguments for the format; if there are not, the results will be unpredictable and likely disastrous. Excess arguments (more than required by the format) are merely ignored. The format string is a character string that contains two types of objects: plain characters and conversion specifications. Plain characters are simply copied verbatim to the output string. Conversion specifications fetch arguments from the argument list and apply formatting to them. printf format specifiers have the following form:
% [flags] [width] [.prec] [{h|l}] type
Here is a complete table of supported formatting options (see any book about C language for more info):

Flags | Meaning
none | Right align (pad spaces or zeros to left)
- | Left align (pad spaces to right)
+ | Always force sign (include prefix '+' before positive values)
z | Don't postfix padding (this option is non-ANSI, i.e. TI specific)
space | Insert space before positive values
# | Prefix octal values with 0 and hex values (>0) with '0x') Force '.' in float output (and prevent trunctation of trailing zeros)
^ | TI-Float format: special character for the exponent and for the minus sign, no '+' prefix in the exponent, 0. instead of 0, no leading zeros if the magnitude is smaller than 1 (this option is non-ANSI, i.e. TI specific)
| | Center the output in the field (this option is non-ANSI, i.e. TI specific)

Width | Meaning
num | Print at least num characters - padded the rest with blanks
0num | (Zero prefixed) Same as above but padded with '0'
* | The width is specified in the arguments list (before value being formatted)

Precision | Meaning
none | Default precision
num | num is number of chars, decimal places, or number of significant digits (num<=16) to display depending on type (see below)
-1 | Default = 6 digits (this option is non-ANSI, i.e. TI specific)
* | The precision is specified in the argument list (before value being formatted)

Size {h|l} | Meaning
h | Force short integer
l | Force long integer

Type | Meaning
d, i | Signed decimal integer
u | Unsigned decimal integer
x | Lowercase hexadecimal integer
X | Uppercase hexadecimal integer
e | Floating point, format [-]d.dddd e[sign]ddd (exponential format)
E | Like 'e' but with uppercase letter for the exponent
f | Floating point, format [-]dddd.dddd
g | Floating point: most compact float format available ('e' or 'f'); this is the most common option, used for most dialog floats
G | Like 'g' but with uppercase letter for the exponent
r | Floating point, engineering form (this option is non-ANSI, i.e. TI specific)
R | Like 'r' but with uppercase letter for the exponent
y | Floating point, mode specified float format (this option is non-ANSI, i.e. TI specific)
Y | Like 'y' but with uppercase letter for the exponent
c | Character
s | String
p | Pointer; principally the same as 'x' - do not use without 'l' modifier
% | None; the character '%' is printed instead

Here is a short demonstration of usage:

    int i, j;
    for (j = F_4x6; j <= F_8x10; j++)
      {
        clrscr ();
        FontSetSys (j);
        for (i = 1; i <= 1000; i++)
          printf ("%d ", i);
        ngetchx ();
      }

Note: In ANSI C, printf is an int function, and it returns the number of printed characters. Due to some practical reasons, this implementation of printf is a void function. This difference is usually not important.

Uses: fputchar, vcbprintf
Used by: gets, getsn