Error "Unexpected '\n' when converting from type LockingTextReader to type int"

Synopsis a at a.com
Wed Sep 7 23:00:23 UTC 2022


Hi! I'm new at programming, just discovered D and I'm loving it 
so far!

I'm learning the basics, so please forgive my noob mistakes and 
questions (as well as my Engrish...).

I'm trying to make this program print both numbers entered by the 
user, it works with the first number (num):

```d
import std.stdio;

void main(){
   struct Fraction
   {
     int num;
     int den;
   }

   Fraction f1;

   write("Num: ");
   readf("%s", &f1.num);

   writef("Num is: %s", f1.num);
}
```


But when I try the same with the second one, I get an error after 
entering the first number:

```d
import std.stdio;

void main(){
   struct Fraction
   {
     int num;
     int den;
   }

   Fraction f1;

   write("Num: ");
   readf("%s", &f1.num);

   write("Den: ");
   readf("%s", &f1.den);

   writef("Num is: %s", f1.num);
   writef("Den is: %s", f1.den);
}
```


*std.conv.ConvException at C:\D\dmd2\windows\bin\..\..\src\phobos\std\conv.d(2526): Unexpected '\n' when converting from type LockingTextReader to type int
0x00C80D74
0x00C80A77
0x00C80559
0x00C8047D
0x00C7FEDB
0x00C7FE4F
0x00C71045
0x00C8CE23
0x00C8CD8F
0x00C8CC0C
0x00C81D6C
0x00C7107F
0x75ADFA29 in BaseThreadInitThunk
0x77957A9E in RtlGetAppContainerNamedObjectPath
0x77957A6E in RtlGetAppContainerNamedObjectPath*


May someone tell me what am I doing wrong? Thank you in advance! 
:)


More information about the Digitalmars-d-learn mailing list