Thread overview | ||||||
---|---|---|---|---|---|---|
|
February 08, 2015 Problem with simple Formatted Input example. | ||||
---|---|---|---|---|
| ||||
This simple program seems to just hang. I am probably missing something. Any help is appreciated. I am using Linux with DMD. Program compiles fine, but when enter a string & press enter, the programs seems to wait forever without returning. import std.stdio; void main() { string firstName; readf(" %s\n", &firstName); writeln(firstName); } Thankyou Venkat |
February 08, 2015 Re: Problem with simple Formatted Input example. | ||||
---|---|---|---|---|
| ||||
Posted in reply to Venkat Akkineni | On 02/07/2015 04:29 PM, Venkat Akkineni wrote:> This simple program seems to just hang. I am probably missing something. > Any help is appreciated. I am using Linux with DMD. Program compiles > fine, but when enter a string & press enter, the programs seems to wait > forever without returning. > > > import std.stdio; > > void main() > { > > string firstName; > readf(" %s\n", &firstName); My earlier understanding was that readf was reading till the end of the input. So, you will see that it will terminate when you press Ctrl-D at the console. I explain that understanding here: http://ddili.org/ders/d.en/strings.html#ix_strings.readln However, when I tried your code again with dmd git head, I see that readf reads the first line of entry *after* I press two Enters on the console. Ali |
February 08, 2015 Re: Problem with simple Formatted Input example. | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ali Çehreli | On 02/07/2015 04:42 PM, Ali Çehreli wrote: > > readf(" %s\n", &firstName); > I see that readf reads the first line of entry *after* I press > two Enters on the console. OK, that is related to the '\n' character that you have in the format string. Also, repeating the space characters has no effect as a single space means "zero or more white space" anyway. Ali |
February 08, 2015 Re: Problem with simple Formatted Input example. | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ali Çehreli | On Sunday, 8 February 2015 at 00:47:46 UTC, Ali Çehreli wrote:
> On 02/07/2015 04:42 PM, Ali Çehreli wrote:
>
> > > readf(" %s\n", &firstName);
>
> > I see that readf reads the first line of entry *after* I press
> > two Enters on the console.
>
> OK, that is related to the '\n' character that you have in the format string. Also, repeating the space characters has no effect as a single space means "zero or more white space" anyway.
>
> Ali
Thankyou, I think it was encoded to be some other character instead of a space. Once I removed the space and re-added it to the string, things seem to work.
I am reading your book. It is a great book for newbies. Thanks a lot for the effort.
|
Copyright © 1999-2021 by the D Language Foundation