Clib.printf()
syntax: |
Clib.printf(formatString[, variables ...]) |
where: |
formatString - string that specifies the final format.
variables - values to be converted to and formatted as a string.
|
return: |
number - characters written, or a negative number if there is an error.
|
description: |
This method writes output to the standard output device according to the format string and returns a number equal to the number of characters written, or a negative number if there is an error. The format string can contain character combinations indicating how following parameters are to be treated. Characters are printed as read to standard output until a percent character, %, is reached. % indicates that a value is to be printed from the parameters following the format string. Each subsequent parameter specification takes from the next parameter in the list following format. A parameter specification has the following form in which square brackets indicate optional fields and angled brackets indicate required fields:
%[flags][width][.precision]<type>
flags may be:
• - • + • blank • # • c, s, d, i, u • o • x, X • f, e, E • g, G
width may be:
• n • 0n • * • .precision
• 0 • n • *
type may be:
• d, i • u • o • x • X • f • e • E • g • G • c • s
To include the % character as a character in the format string, you must use two % characters together, %%, to prevent the computer from trying to interpret it as one of the above forms.
|
see: |
|
example: |
//Each of the following lines shows // a printf example followed by what would show // on the output in boldface:
Clib.printf("Hello world!") // Hello world! Clib.printf("I count: %d %d %d.",1,2,3) // I count: 1 2 3 var a = 1; var b = 2; Clib.printf("%d %d %d", a, b, a +b) // 1 2 3 |