A good number of methods exist in Euphoria that can be used to display information to output. However, there is one method that is usually favored among the rest, the printf()
method. This method is used to print formatted strings to the display.
A formatted string will contain a variable placeholder in it that will be replaced with the value of such a variable at the run time.
printf(fn,format,valueToPrint)
fn
: This parameter indicates the file or device number to write to. For files, it is always 1
when the file is found or available as indicated by the open function. It is an integer value.format
: This holds the text to print, if any, and a format specifier, which will be replaced by the valueToPrint
parameter. It is a double quoted sequence.valueToPrint
: The variable whose value will be used in place of the format specifier. It is of the type
object, which implies it can be of any data type.The return value is an object.
In the code snippet below, a sample illustration of how the printf()
method can be used is shown.
--define some atom variablesatom age =30, height = 5.7--define a sequencesequence name = "Mr Kyle"-- print a formated string to displayprintf(1,"I have a neighbor, %s, he is %.1f tall and is %d years young",{name,height,age} )
age
and height
.printf()
method. The first parameter passed to the printf()
method is 1
, which is the value of the standard output. The next parameter is a formatted string, which contains some format specifiers:
%s
: To be replaced by the value of the sequence name
.%.1f
: This specifies that the height value should be displayed with one decimal place and lastly.%d
: This will be replaced by the integer atom age
.
The last parameter passed to the function is the variable whose value will be substituted into the formatted string. They are placed in a sequence because they are multiple and are arranged in order of appearance in the formatted string.