readf with strings

GreatEmerald pastas4 at gmail.com
Wed Jun 22 07:57:57 PDT 2011


This should be a very elementary question. How do you get a string off stdin?
Or an integer, or a boolean, for that matter? If I use this:

  float MyFloat;
  string MyString;
  readf("%f", &MyFloat);
  writeln(MyFloat);
  readf("%s", &MyString);
  writeln(MyString);

I get the float printed correctly, but when it asks to input the string,
whatever I input gets ignored - I can't reach the writeln part in any way and
I have to forcibly close the program. The same thing is with ints - if I enter
an int, it acts as if I didn't enter anything at all. But floats work fine for
some reason. Any thoughts about what is happening there?

I'm using openSUSE 11.4 and DMD 2.053.


More information about the Digitalmars-d-learn mailing list