Format Characters for Methods That Print

This topic describes format characters for methods that print. The following methods can perform print operations:

Each of these methods prints each character while it reads the input until the method encounters a percentage symbol (%). This symbol instructs that method to use the following format to print a value:

%[flags][width][.precision]type

To include the % symbol as a character in the string, you use two consecutive percentage symbols (%%).

Characters That Format Values

The following table describes characters that format a value.

Character Description Example Statement and Output

-

Left justification in the field with space padding or right justification with zero or space padding.

fprintf(file, "[%-8i]", 26);

[26 ]

+

Force numbers to begin with a plus symbol (+) or a minus symbol (-).

fprintf(file, "%+i", 26);

+26

space

A negative value that begins with a minus symbol (-). A positive value begins with a space.

fprintf(file, "[% i]", 26);

[ 26]

#

Append one of the following symbols to the pound (#) character to display the output in one of the following forms:

  • o. Prefix a zero to nonzero octal output.

  • x or X. Prefix 0x or 0X to the output, which indicates hexadecimal.

  • f. Include a decimal point even if no digits follow the decimal point.

  • e or E. Include a decimal point even if no digits follow the decimal point, and display the output in scientific notation.

  • g or G. Include a decimal point even if no digits follow the decimal point, display the output in scientific notation, depending on precision, and leave trailing zeros in place.

fprintf(file, "%#o", 26);

032

fprintf(file, "%#x", 26);

0x1A

fprintf(file, "%#.f", 26);

26.

fprintf(file, "%#e", 26);

2.600000e+001

fprintf(file, "%#g", 26);

26.0000

f

Floating-point of the format [-]dddd.dddd.

fprintf(file, "%f", 26.735);

26.735000

e

Floating-point of the format [-]d.ddde+dd or [-]d.ddde-dd.

fprintf(file, "%e", 26.735);

2.673500e+001

E

Floating-point of the format [-]d.dddE+dd or [-]d.dddE-dd.

fprintf(file, "%E", 26.735);

2.673500E+001

g

Floating-point number of f or e type, depending on precision.

fprintf(file, "%g", 26.735);

26.735

G

Floating-point number of F or E type, depending on precision.

fprintf(file, "%G", 26.735);

26.735

c

Character. For example, a, b, or 8.

fprintf(file, "%c", 'a');

a

s

String.

fprintf(file, "%s", "Test");

Test

Characters That Determine Width

The following table describes characters that determine width.

Character Description Example Statement and Output

n

At least n characters are output. If the value is less than n characters, then Siebel eScript pads that precedes the output with spaces.

fprintf(file, "[%8s]", "Test");

[ Test]

0n

At least n characters are output pads that precedes the output with zeros.

fprintf(file, "%08i", 26);

00000026

*

The next value in the argument list is an integer that specifies the output width.

fprintf(file, "[%*s]", 8, "Test");

[ Test]

Characters That Determine Precision

The following table describes characters that determine precision. If you specify precision, then you must begin the precision format with a period (.) and you must use one of the forms described in Format Characters for Methods That Print.

Character Description Example Statement and Output

.0

For floating-point type. No decimal point is output.

fprintf(file, "%.0f", 26.735);

26

.n

Output is n characters. If the value is a floating-point number, then the output is n decimal places.

Assume you specify a Width value and a .n Precision value when you format a floating point number. In this situation, to determine the width of the output and to determine if it must pad the output, the method counts the decimal point and the characters that occur before and after the decimal point. For example:

fprintf(file, "%10.2f", 26.735);

[     26.73]

fprintf(file, "%.2f", 26.735);

26.73

.*

The next value in the argument list is an integer that specifies the precision width.

fprintf(file, "%.*f", 1, 26.735);

26.7

Characters That Determine Character Type

The following table describes characters that determine character type.

Character Description Example Statement and Output

d,i

Signed integer.

fprintf(file, "%i", 26);

26

u

Unsigned integer.

fprintf(file, "%u", -1);

4294967295

o

Octal integer.

fprintf(file, "%o", 26);

32

x

Hexadecimal integer using 0 through 9 and a, b, c, d, e, or f.

fprintf(file, "%x", 26);

1a

X

Hexadecimal integer using 0 through 9 and A, B, C, D, E, or F.

fprintf(file, "%X", 26); 1A

f

Floating-point of the format [-]dddd.dddd.

fprintf(file, "%f", 26.735);

26.735000

e

Floating-point of the format [-]d.ddde+dd or [-]d.ddde-dd.

fprintf(file, "%e", 26.735);

2.673500e+001

E

Floating-point of the format [-]d.dddE+dd or [-]d.dddE-dd.

fprintf(file, "%E", 26.735);

2.673500E+001

g

Floating-point number of f or e, depending on precision.

fprintf(file, "%g", 26.735);

26.735

G

Floating-point number of F or E, depending on precision.

fprintf(file, "%G", 26.735);

26.735

c

Character. For example, a, b, 8.

fprintf(file, "%c", 'a');

a

s

String.

fprintf(file, "%s", "Test");

Test