I\'m having a very strange issue with a D program. read(\" %s\", variable) works fine by itself and readln(variable) works fine by itself, but when I put the two together, readl
This is a common mistake with the readf and scanf function from C too. readf is pretty exact about the format string and whitespace. With your string there, it reads the value then stops at the first whitespace it sees... which happens to be the newline.
If you were to do this:
Enter a number: 123 bill
It would print What is your name? Hello bill!
because it stopped at the space, then readln picked that up until end of line.
If you do 123, hit enter, then enter your name, readf stops at the newline character... which readln then picks up as an empty line.
Easiest fix is to just tell readf to consume the newline too:
readf(" %s\n", &x);
Then readln will be starting with an empty buffer and be able to get what it needs to get.