readf interferes with readln

Bastiaan Veelo via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Apr 27 01:32:38 PDT 2017


Hi,

I am having trouble explaining the following to someone learning 
D. Can someone explain why readln has different behaviour when it 
is preceded by readf?

Suppose we want to not end the program before the user presses 
Enter by having readln at the end of main():

```
import std.stdio;

void main()
{
     int num;
     write("Give a number ");
     readf(" %s", num);
     writeln("Thanks");
     readln;
     readln;
}
```

In this example this requires twice readln. When you comment out 
readf, you need readln only once.

Thanks!




More information about the Digitalmars-d-learn mailing list