www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - scanf in MemoryStream

reply sailormoontw <sailormoontw_member pathlink.com> writes:
The code is as follows, I assume this code would work in older version of D
compiler, but in current version of D compiler, it halts. Is there anything
changed in the scanf function of MemoryStream, and how should I fix to code?

Thanks ^_^



private import std.stream;

void main()
{
MemoryStream ms = new MemoryStream("1.23 4.56 7.89 9.01 ");
float a, b, c, d;
ms.scanf("%f %f %f %f", &a, &b, &c, &d);
}
May 20 2006
next sibling parent Carlos Santander <csantander619 gmail.com> writes:
sailormoontw escribió:
 The code is as follows, I assume this code would work in older version of D
 compiler, but in current version of D compiler, it halts. Is there anything
 changed in the scanf function of MemoryStream, and how should I fix to code?
 
 Thanks ^_^
 
 
 
 private import std.stream;
 
 void main()
 {
 MemoryStream ms = new MemoryStream("1.23 4.56 7.89 9.01 ");
 float a, b, c, d;
 ms.scanf("%f %f %f %f", &a, &b, &c, &d);
 }
 
 

Before the scanf, I think you need ms.position = 0; -- Carlos Santander Bernal
May 20 2006
prev sibling parent reply "Chris Miller" <chris dprogramming.com> writes:
On Sat, 20 May 2006 07:21:43 -0400, sailormoontw  
<sailormoontw_member pathlink.com> wrote:

 The code is as follows, I assume this code would work in older version  
 of D
 compiler, but in current version of D compiler, it halts. Is there  
 anything
 changed in the scanf function of MemoryStream, and how should I fix to  
 code?

 Thanks ^_^

 private import std.stream;

 void main()
 {
 MemoryStream ms = new MemoryStream("1.23 4.56 7.89 9.01 ");
 float a, b, c, d;
 ms.scanf("%f %f %f %f", &a, &b, &c, &d);
 }

hahaha... not laughing at you, but it's a funny side affect: There is no scanf in Stream or MemoryStream, but it is accessible because std.c.stdio is imported inside Stream, making the stdin scanf available. stdin scanf is waiting for you to type.
May 20 2006
parent Carlos Santander <csantander619 gmail.com> writes:
Chris Miller escribió:
 On Sat, 20 May 2006 07:21:43 -0400, sailormoontw 
 <sailormoontw_member pathlink.com> wrote:
 
 The code is as follows, I assume this code would work in older version 
 of D
 compiler, but in current version of D compiler, it halts. Is there 
 anything
 changed in the scanf function of MemoryStream, and how should I fix to 
 code?

 Thanks ^_^

 private import std.stream;

 void main()
 {
 MemoryStream ms = new MemoryStream("1.23 4.56 7.89 9.01 ");
 float a, b, c, d;
 ms.scanf("%f %f %f %f", &a, &b, &c, &d);
 }

hahaha... not laughing at you, but it's a funny side affect: There is no scanf in Stream or MemoryStream, but it is accessible because std.c.stdio is imported inside Stream, making the stdin scanf available. stdin scanf is waiting for you to type.

Use ms.readf, then. -- Carlos Santander Bernal
May 20 2006