Re: Calling readln() after readf

2022-07-06 Thread Gary Chike via Digitalmars-d-learn
Thanks for the extra info guys! D is one of my favorite languages I'm currently learning. :)

Re: Calling readln() after readf

2022-07-05 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/5/22 8:14 PM, Gary Chike wrote: On Monday, 20 June 2022 at 16:08:33 UTC, Ali Çehreli wrote: On 6/20/22 07:00, Gary Chike wrote: > Would it be appropriate to forego `readf` > and read input as a string using `readln` ,benefiting from the `strip` > function, then convert to their

Re: Calling readln() after readf

2022-07-05 Thread Ali Çehreli via Digitalmars-d-learn
On 7/5/22 17:14, Gary Chike wrote: > So, in order to use `parse!int()`, I would need to separate it into two > statements with a variable acting as an intermediary: > ``` > auto input = readln(); > auto age = parse!int(input); Exactly. parse takes the input by reference (necessitating an

Re: Calling readln() after readf

2022-07-05 Thread Gary Chike via Digitalmars-d-learn
On Monday, 20 June 2022 at 16:08:33 UTC, Ali Çehreli wrote: On 6/20/22 07:00, Gary Chike wrote: > Would it be appropriate to forego `readf` > and read input as a string using `readln` ,benefiting from the `strip` > function, then convert to their appropriate datatype Makes sense. The following

Re: Calling readln() after readf

2022-06-26 Thread Gary Chike via Digitalmars-d-learn
On Monday, 20 June 2022 at 16:08:33 UTC, Ali Çehreli wrote: Makes sense. The following are related as well: https://dlang.org/library/std/conv/parse.html https://dlang.org/library/std/format/read/formatted_read.html Ali Thank you so much for your input! Cheers! :)

Re: Calling readln() after readf

2022-06-20 Thread Ali Çehreli via Digitalmars-d-learn
On 6/20/22 07:00, Gary Chike wrote: > Would it be appropriate to forego `readf` > and read input as a string using `readln` ,benefiting from the `strip` > function, then convert to their appropriate datatype Makes sense. The following are related as well:

Re: Calling readln() after readf

2022-06-20 Thread Gary Chike via Digitalmars-d-learn
I should have qualified the above with: _ and I will be performing operations on the numeric datatype, since just outputting simply strings, as in the above example, would require nothing more than string data types. :) ```d module hello_world; import std.stdio; import std.string; // strip()

Re: Calling readln() after readf

2022-06-20 Thread Gary Chike via Digitalmars-d-learn
On Monday, 20 June 2022 at 00:43:17 UTC, Ali Çehreli wrote: ... But when the program interacts with piped data, there may be multiple \n characters and all of those might have to be ignored before reading the next non-empty line. So you may want to do readln.strip multiple times? I don't

Re: Calling readln() after readf

2022-06-19 Thread Ali Çehreli via Digitalmars-d-learn
On 6/19/22 15:52, Gary Chike wrote: > On Saturday, 24 April 2021 at 22:13:45 UTC, Ali Çehreli wrote: >> On 4/24/21 7:46 AM, PinDPlugga wrote: >> ... >> As a general solution, you can use a function like this: >> >> auto readLine(S = string)(File file = stdin) { >> while (!file.eof) { >>

Re: Calling readln() after readf

2022-06-19 Thread Gary Chike via Digitalmars-d-learn
On Saturday, 24 April 2021 at 22:13:45 UTC, Ali Çehreli wrote: On 4/24/21 7:46 AM, PinDPlugga wrote: ... As a general solution, you can use a function like this: auto readLine(S = string)(File file = stdin) { while (!file.eof) { auto line = file.readln!S.strip; if (!line.empty) {

Re: Calling readln() after readf

2021-04-24 Thread Ali Çehreli via Digitalmars-d-learn
On 4/24/21 7:46 AM, PinDPlugga wrote: > write("Please enter a number: "); > double number; > readf(" %s", number); Just to make sure, this is a common issue for other languages as well. As the explanation, the character ('\n') that you injected into stdin by pressing Enter is

Re: Calling readln() after readf

2021-04-24 Thread Imperatorn via Digitalmars-d-learn
On Saturday, 24 April 2021 at 14:46:06 UTC, PinDPlugga wrote: I didn't want to necropost, but I ran into the same behaviour as in this post: https://forum.dlang.org/post/yfybveovbknvvxmio...@forum.dlang.org and was just curious to understand it better. [...]

Calling readln() after readf

2021-04-24 Thread PinDPlugga via Digitalmars-d-learn
I didn't want to necropost, but I ran into the same behaviour as in this post: https://forum.dlang.org/post/yfybveovbknvvxmio...@forum.dlang.org and was just curious to understand it better. If I call readln() after having previously called readf(), it does not behave as expected: ```d import