Formatted Input
This lesson explains how the format of data can be specified at the time of input.
We'll cover the following...
What is formatted input? #
It is possible to specify the format of the data expected to be read as input using readf
. It specifies both the data that should be read and the characters that should be ignored.
D’s input format specifiers are similar to the ones present in the C language.
As previously used, the format specifier " %s"
reads the data according to the type of the variable. For example, since the type of the variable used in readf
is double
, the characters read at the input would be treated as a floating point number:
double number;
readf(" %s", &number);
The format string can contain three types of information:
-
The space character: indicates zero or more whitespace characters at the input and specifies that all of those characters should ...