Needing to match white space during formatted read

Ali Çehreli acehreli at yahoo.com
Tue Mar 8 13:48:33 PST 2011


On 03/04/2011 11:21 AM, Ali Çehreli wrote:
 > I am asking this question from the point of view of someone who is in
 > the process of replacing std.cstream with std.stdio in his book that
 > targets novices. There are many sample programs in the book where the
 > user interacts with the program through the console.

Console interaction is for novices. There are no novices here.

 > I would like to know whether the changes that I will be making will be
 > correct.

Just make them correctly.

 > import std.stdio;
 >
 > void main()
 > {
 > int i;
 > int j;
 >
 > readf("%d%d", &i, &j);
 > }
 >
 > 1) The code above does not terminate when I interact with the program at
 > the console and enter "1 2" from the keyboard (without the double quotes)
 >
 > I understand that the reason is the space character that I had to type
 > between the two values. The solution is to use a format string that must
 > take account for that white space.
 >
 > Does that mean that we must always use spaces before format specifiers
 > as in " %d %d" (and even better: " %s %s")?

That's sounds right.

 > 2) The equivalent C program does not require a space between format
 > specifiers. Is this departure from C intentional?

Forget C. Do D.

 > 3) The program above behaves differently when the input is piped from
 > the output of another program:
 >
 > $ echo '1 2' | ~/deneme/d/deneme
 > std.conv.ConvException at std/conv.d(37): std.conv(1161): Can't convert
 > value ` 2
 > ' of type LockingTextReader to type int
 > ----------------

Then just don't pipe.

 > That probably needs a bug report but where do you think the difference
 > originates from: keyboard, echo, console, D runtime, Phobos, something
 > else?

Please file a bug report.

 > Thank you,
 > Ali

Thank me,
Ali



More information about the Digitalmars-d mailing list