www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - std.stream.stdin.read bug ?

reply "Asaf Karagila" <kas1 netvision.net.il> writes:
004020BE  |> /8D45 FC              /LEA     EAX, [LOCAL.1]
004020C1  |. |50                          |PUSH    EAX
004020C2  |. |A1 70BB4100       |MOV     EAX, DWORD PTR DS:[41BB70]
004020C7  |. |8B08                     |MOV     ECX, DWORD PTR DS:[EAX]
004020C9  |. |FF51 38                |CALL    NEAR DWORD PTR DS:[ECX+38]
004020CC  |. |837D FC 02         |CMP     [LOCAL.1], 2
004020D0  |. |76 05                    |JBE     SHORT hello.004020D7
004020D2  |. |8B45 FC              |MOV     EAX, [LOCAL.1]
004020D5  |. |C9                        |LEAVE
004020D6  |. |C3                        |RET

is compiled from this code:
    std.stream.stdin.read(input);
    if (input > 2) return input;

the LOCAL.1 address is pointed to the read(), but is not changing to the 
input value.
instead i get '168636723' for every input i give in..

anyone experienced with it ?
is it a compiler bug or my problem ?

Cheers,
Asaf 
Oct 09 2004
parent reply Ben Hinkle <bhinkle4 juno.com> writes:
Asaf Karagila wrote:

 004020BE  |> /8D45 FC              /LEA     EAX, [LOCAL.1]
 004020C1  |. |50                          |PUSH    EAX
 004020C2  |. |A1 70BB4100       |MOV     EAX, DWORD PTR DS:[41BB70]
 004020C7  |. |8B08                     |MOV     ECX, DWORD PTR DS:[EAX]
 004020C9  |. |FF51 38                |CALL    NEAR DWORD PTR DS:[ECX+38]
 004020CC  |. |837D FC 02         |CMP     [LOCAL.1], 2
 004020D0  |. |76 05                    |JBE     SHORT hello.004020D7
 004020D2  |. |8B45 FC              |MOV     EAX, [LOCAL.1]
 004020D5  |. |C9                        |LEAVE
 004020D6  |. |C3                        |RET
 
 is compiled from this code:
     std.stream.stdin.read(input);
     if (input > 2) return input;
 
 the LOCAL.1 address is pointed to the read(), but is not changing to the
 input value.
 instead i get '168636723' for every input i give in..
 
 anyone experienced with it ?
 is it a compiler bug or my problem ?
 
 Cheers,
 Asaf

I'm not sure why read() is behaving like it is, but I would try using scanf() instead. read() is for binary input. scanf() is for text input. Are you typing in values from the console or are you piping something into stdin? -Ben
Oct 09 2004
parent reply "Asaf Karagila" <kas1 netvision.net.il> writes:
"Ben Hinkle" <bhinkle4 juno.com> wrote in message 
news:ck8or5$k9t$1 digitaldaemon.com...
 Asaf Karagila wrote:

 004020BE  |> /8D45 FC              /LEA     EAX, [LOCAL.1]
 004020C1  |. |50                          |PUSH    EAX
 004020C2  |. |A1 70BB4100       |MOV     EAX, DWORD PTR DS:[41BB70]
 004020C7  |. |8B08                     |MOV     ECX, DWORD PTR DS:[EAX]
 004020C9  |. |FF51 38                |CALL    NEAR DWORD PTR DS:[ECX+38]
 004020CC  |. |837D FC 02         |CMP     [LOCAL.1], 2
 004020D0  |. |76 05                    |JBE     SHORT hello.004020D7
 004020D2  |. |8B45 FC              |MOV     EAX, [LOCAL.1]
 004020D5  |. |C9                        |LEAVE
 004020D6  |. |C3                        |RET

 is compiled from this code:
     std.stream.stdin.read(input);
     if (input > 2) return input;

 the LOCAL.1 address is pointed to the read(), but is not changing to the
 input value.
 instead i get '168636723' for every input i give in..

 anyone experienced with it ?
 is it a compiler bug or my problem ?

 Cheers,
 Asaf

I'm not sure why read() is behaving like it is, but I would try using scanf() instead. read() is for binary input. scanf() is for text input. Are you typing in values from the console or are you piping something into stdin? -Ben

input is UINT, i forgot to mention that.. sorry.. and i am typing into the console. Cheers, Asaf
Oct 09 2004
parent reply Ben Hinkle <bhinkle4 juno.com> writes:
On Sat, 9 Oct 2004 15:31:38 +0200, "Asaf Karagila"
<kas1 netvision.net.il> wrote:

"Ben Hinkle" <bhinkle4 juno.com> wrote in message 
news:ck8or5$k9t$1 digitaldaemon.com...
 Asaf Karagila wrote:

 004020BE  |> /8D45 FC              /LEA     EAX, [LOCAL.1]
 004020C1  |. |50                          |PUSH    EAX
 004020C2  |. |A1 70BB4100       |MOV     EAX, DWORD PTR DS:[41BB70]
 004020C7  |. |8B08                     |MOV     ECX, DWORD PTR DS:[EAX]
 004020C9  |. |FF51 38                |CALL    NEAR DWORD PTR DS:[ECX+38]
 004020CC  |. |837D FC 02         |CMP     [LOCAL.1], 2
 004020D0  |. |76 05                    |JBE     SHORT hello.004020D7
 004020D2  |. |8B45 FC              |MOV     EAX, [LOCAL.1]
 004020D5  |. |C9                        |LEAVE
 004020D6  |. |C3                        |RET

 is compiled from this code:
     std.stream.stdin.read(input);
     if (input > 2) return input;

 the LOCAL.1 address is pointed to the read(), but is not changing to the
 input value.
 instead i get '168636723' for every input i give in..

 anyone experienced with it ?
 is it a compiler bug or my problem ?

 Cheers,
 Asaf

I'm not sure why read() is behaving like it is, but I would try using scanf() instead. read() is for binary input. scanf() is for text input. Are you typing in values from the console or are you piping something into stdin? -Ben

input is UINT, i forgot to mention that.. sorry.. and i am typing into the console. Cheers, Asaf

If you are typing at the console you need to use scanf. For example, import std.stream; int main() { uint input; stdin.scanf("%u",&input); stdout.writefln("you typed ", input); return 0; }
Oct 09 2004
parent "Asaf Karagila" <kas1 netvision.net.il> writes:
"Ben Hinkle" <bhinkle4 juno.com> wrote in message 
news:gq1gm0l9tv2pvn05tp27m8rs5ekomhu3fu 4ax.com...
 On Sat, 9 Oct 2004 15:31:38 +0200, "Asaf Karagila"
 <kas1 netvision.net.il> wrote:

"Ben Hinkle" <bhinkle4 juno.com> wrote in message
news:ck8or5$k9t$1 digitaldaemon.com...
 Asaf Karagila wrote:

 004020BE  |> /8D45 FC              /LEA     EAX, [LOCAL.1]
 004020C1  |. |50                          |PUSH    EAX
 004020C2  |. |A1 70BB4100       |MOV     EAX, DWORD PTR DS:[41BB70]
 004020C7  |. |8B08                     |MOV     ECX, DWORD PTR DS:[EAX]
 004020C9  |. |FF51 38                |CALL    NEAR DWORD PTR 
 DS:[ECX+38]
 004020CC  |. |837D FC 02         |CMP     [LOCAL.1], 2
 004020D0  |. |76 05                    |JBE     SHORT hello.004020D7
 004020D2  |. |8B45 FC              |MOV     EAX, [LOCAL.1]
 004020D5  |. |C9                        |LEAVE
 004020D6  |. |C3                        |RET

 is compiled from this code:
     std.stream.stdin.read(input);
     if (input > 2) return input;

 the LOCAL.1 address is pointed to the read(), but is not changing to 
 the
 input value.
 instead i get '168636723' for every input i give in..

 anyone experienced with it ?
 is it a compiler bug or my problem ?

 Cheers,
 Asaf

I'm not sure why read() is behaving like it is, but I would try using scanf() instead. read() is for binary input. scanf() is for text input. Are you typing in values from the console or are you piping something into stdin? -Ben

input is UINT, i forgot to mention that.. sorry.. and i am typing into the console. Cheers, Asaf

If you are typing at the console you need to use scanf. For example, import std.stream; int main() { uint input; stdin.scanf("%u",&input); stdout.writefln("you typed ", input); return 0; }

thanks, its working now.. Cheers, Asaf
Oct 09 2004