Difference between revisions of "Programmer Guide/Command Reference/WRITE"

From STX Wiki
Jump to navigation Jump to search
Line 3: Line 3:
 
  WRITE <var>file</var> <var>format</var> <var>args</var> /Format [/Newline &hellip; /Newline]
 
  WRITE <var>file</var> <var>format</var> <var>args</var> /Format [/Newline &hellip; /Newline]
  
This {{Stx}} command writes (hence its name) text into a file connected to a file item. If ''no'' <code>/Newline</code> option is specified, the text of the next <code>WRITE</code> command will be placed in the same line. Format strings are described in [[Programmer_Guide/General_Descriptions/Format_Strings_and_Rules|Format Strings and Rules]].
+
This {{Stx}} command writes (hence its name) text to a file assigned to a file item. If ''no'' <code>/Newline</code> option is specified, the text of the next <code>WRITE</code> command will be placed in the same line. Format strings are described in [[Programmer_Guide/General_Descriptions/Format_Strings_and_Rules|Format Strings and Rules]].
  
 
;<var>file</var>
 
;<var>file</var>

Revision as of 14:53, 8 May 2014

WRITE file text [/Newline … /Newline]
WRITE file format args /Format [/Newline … /Newline]

This STx command writes (hence its name) text to a file assigned to a file item. If no /Newline option is specified, the text of the next WRITE command will be placed in the same line. Format strings are described in Format Strings and Rules.

file
The name of a file item (must, obviously, be open for write access).
text
The output text (unformatted, written "as is").
format
The format string (see Format Strings and Rules). There must be a corresponding args argument for each "% format" tag in format becauseSTx will not check if the number of arguments supplied matches the given format string and will, hence, crash heavily if there is any mistake.
args
The arguments (one for each format tag in format). Note that STx will not check if the number of arguments supplied matches the given format string and will, hence, crash heavily if there is any mistake.

Example

#f := $(new file * test.txt /T /W)WRITE $#f 'this is %d format for %3.0f numbers' 1 0.2*10 /Newline /Format

The line "this is 1 format for 2 numbers" will be written to the file. Note that this is also an example of horribly bad programming style, not checking if the inline NEW FILE command succeeded, and happily executing garbage when it did not.