Product Documentation
Cadence SKILL Language Reference
Product Version IC23.1, November 2023

fprintf

fprintf( 
p_port 
t_formatString 
[ g_arg1 ... ] 
) 
=> t

Description

Writes formatted output to a port.

The fprintf function writes formatted output to the port given as the first argument. The optional arguments following the format string are printed according to their corresponding format specifications.

printf is identical to fprintf except that it does not take the p_port argument and the output is written to poport.

Output is right justified within a field by default unless an optional minus sign “-” immediately follows the % character, which will then be left justified. To print a percent sign, you must use two percent signs in succession. You must explicitly put \n in your format string to print a newline character and \t for a tab.

Common Output Format Specifications
Format Specification Type(s) of Argument Prints

%d

fixnum

Integer in decimal radix

%o

fixnum

Integer in octal

%x

fixnum

Integer in hexadecimal

%f

flonum

Floating-point number in the style
[-]ddd.ddd

%e

flonum

Floating-point number in the style
[-]d.ddde[-]ddd

%g

flonum

Floating-point number in style f or e, whichever gives full precision in minimum space

Qualifying %g with width may cause imprecise results to be printed.

%s

string, symbol

Prints out a string (without quotes) or the print name of a symbol

%c

string, symbol

The first character

%n

fixnum, flonum

Number

%P

list

Point

%B

list

Box

%N

any

Prints an object in the old style, that is, does not call the printself function

%L

list

Default format for the data type

Print behavior depends on the value of the printpretty variable:

If printpretty is nil, this behaves like %N

If printpretty is non-nil (default), %L uses printself for standard objects

%A

any

Prints any type of object using the printself representation

The t_formatString argument is a conversion control string containing directives listed in the table above. The %L, %P, and %B directives ignore the width and precision fields.

%[-][width][.precision]conversion_code 
[-] = left justify
[width] = minimum number of character positions
[.precision] = number of characters to be printed
conversion_code

Arguments

p_port

Output port to write to.

t_formatString

Characters to be printed verbatim, intermixed with format specifications prefixed by the % sign.

g_arg1

The arguments following the format string are printed according to their corresponding format specifications.

Value Returned

t

Prints the formatted output and returns t.

Examples

p = outfile("power.out")
=> port:"power.out"
for(i 0 15 fprintf(p "%20d %-20d\n" 2**i 3**i))
=> t
close( p)

At this point the power.out file has the following contents.

The following example shows the use of %A, which calls the printself method.

defmethod(printself ((obj fixnum))
sprintf(nil "FIXNUM{%d}" obj));;Defines the printself method
printf("Print control A returns: %A\n" 42);; %A calls the printself method
=> Print control A returns: FIXNUM{42}

The following example shows the use of %L, which calls printself only for standard objects.

defmethod(printself ((obj fixnum))
sprintf(nil "FIXNUM{%d}" obj));;Defines the printself method
printf("Print control L returns: %L\n" 42)
=> Print control L returns: 42

The following example shows the use of %L, %A, and %N print controls with printf when printing standard objects. %A prints the same result as %L and %N does not call the printself method.

defclass(A () ());; Defines a class A
defmethod(printself ((obj A));; Defines the printself method
sprintf(nil "OBJ_A{%L}" obj))
printf("Print control L returns: %L\n" Instance('A))
printf("Print control A returns: %A\n" Instance('A))
printf("Print control N returns: %N\n" Instance('A))
=> Print control L returns: OBJ_A{stdobj@0x83bf024}
Print control A returns: OBJ_A{stdobj@0x83bf024}
Print control N returns: stdobj@0x83bf03c

Related Topics

close

fscanf, scanf, sscanf

outfile

printf


Return to top
 ⠀
X