Reading and Writing

Reading and Writing

Formatted output in Aten is based largely on string formatting in C, so if you're familiar with C then this should be a breeze. If you're a Soldier of Fortran, then the principles are very similar. If you're familiar with neither, then now's the time to learn.

[Note]See Also:

Formatted Output

Formatted output corresponds to output to either the screen or to files, and is used in the following commands:

Table 4.7. Formatted output commands

CommandFunction
errorWrite a message to the screen and immediately terminate execution of the current script / filter / command structure
printfWrite a message to the screen
verboseWrite a message to the screen, provided verbose output mode is on
writelinefWrite a formatted line to the current output file
writevarfWrite a formatted string to a variable (equivalent to the C 'sprintf' command)

Note that all are called the same as their ((Delimited Reading and Writing|delimited counterparts)), but with the addition of an 'f' at the end of the name.

Basic Strings

Formatting a string for output, as mentioned elsewhere on numerous occasions, works the same as for C. The C 'printf' command (equivalent to the command of the same name in Aten) takes a character string as its first argument, and at its simplest, this is all that is required:

printf("Hello");

This prints 'Hello' to the screen (minus the quotes). Importantly, however, a newline character is not printed, meaning that the next thing you try and printf will appear on the same line. For instance:

printf("Hello");
printf("There.");

would output:

HelloThere.

The end of a character constant in the printf command does not implicitly mean 'and this is the end of the line' - you must indicate the end of the line yourself by placing '\n' at the point where you wish the line to end. So:

printf("Hello\n");
printf("There.");

would output:

Hello
There.

Newlines (\n) are an example of escaped characters - the backslash '\' indicates that the following character, in this case 'n', is not to be treated as a normal 'n', but instead will take on its alternative 'meaning', in this case a newline. There are one or two other escaped characters recognised - see Escaped Characters for a list. Note that the newline token can appear anywhere in the string, and any number of times. So:

printf("Hello\nThere\n.");

would output:

Hello
There
.