How can the SilkTest Printf() function be used?
The Printf() function is used to print a formatted value to the results file. The user can then specify the format of each argument. The format string can include any Ansi C Printf format specifiers, including:
%s (if the argument that follows is a string)
%d (if the argument that follows is an integer)
%o (if the argument that follows is an integer you want formatted in octal format)
%x (if the argument that follows is an integer you want formatted in hexadecimal format)
%f (if the argument that follows is a real number)
Any of these format characters can be preceded with an integer to specify the width to use in the output. Use an asterisk (*) to determine the width from an argument in the list, for example:
Printf ("%*s", 5, "abc")
The above will print the string "abc" preceded by 5 spaces.
By default, the output is right-justified. A negative width causes left-justification.
For real numbers, a second number can also be specified, which is the precision of the output, in the form width.precision. An asterisk can be used as the precision, to read the precision from the argument list.
Printf does not automatically supply a new-line character at the end of the line, as Print does. To output a carriage return at the end of the line, use the text "\n" in the format string. To output a backslash (\), enter two backslashes in the format string, as in the following:
Printf ("%s\\%s", sMyString, sMyString)
The above will print: abc\abc
Similarly, to output a percent sign (%), specify two percent signs in the format string.
Examples of the use of Printf():
testcase PrintfExample () STRING sMyString = "abc" INTEGER iMyInt = 123 NUMBER nMyReal = 45.7 Printf ("%s", sMyString) // prints abc Printf ("%4d", iMyInt) // prints 123 Printf ("%4.2f", nMyReal) // prints 45.70 Printf ("%s%d", sMyString, iMyInt) // prints abc123 Printf ("%-4s%d", sMyString, iMyInt) // prints abc 123