Re: Reading whitespace separated strings from stdin?

2015-04-22 Thread TheGag96 via Digitalmars-d-learn
On Tuesday, 21 April 2015 at 03:44:16 UTC, weaselcat wrote: snip Wow, that's a damn good solution... I didn't know that readln() could take an argument that it stops at once it finds. Now the thing is, this program is supposed to be a reverse Polish notation calculator. A human using this p

Re: Reading whitespace separated strings from stdin?

2015-04-20 Thread weaselcat via Digitalmars-d-learn
On Tuesday, 21 April 2015 at 01:31:58 UTC, TheGag96 wrote: Hi guys! I had this homework assignment for data structures that has a pretty easy solution in C++. Reading input like this... 1 2 3 # $ 4 3 * ! # 20 3 / # $ # 62 # $ 2 3 8 * + # 4 48 4 2 + / # SUM # $ 1 2 3 4 5 # R # @ ...where "@" d

Re: Reading whitespace separated strings from stdin?

2015-04-20 Thread Adam D. Ruppe via Digitalmars-d-learn
On Tuesday, 21 April 2015 at 02:04:24 UTC, TheGag96 wrote: It'll just leave some trailing whitespace, which I don't want. oh it also keeps the newlines attached. Blargh. Well, forget the D functions, just use the C functions: import core.stdc.stdio; void main() { char[16] token;

Re: Reading whitespace separated strings from stdin?

2015-04-20 Thread TheGag96 via Digitalmars-d-learn
On Tuesday, 21 April 2015 at 01:46:53 UTC, Adam D. Ruppe wrote: I think this should work: import std.stdio; void main() { string token; while(readf("%s ", &token)) writeln(token); } Have you tried that? What is wrong with it if you have? It'll just leave some

Re: Reading whitespace separated strings from stdin?

2015-04-20 Thread Adam D. Ruppe via Digitalmars-d-learn
I think this should work: import std.stdio; void main() { string token; while(readf("%s ", &token)) writeln(token); } Have you tried that? What is wrong with it if you have?

Reading whitespace separated strings from stdin?

2015-04-20 Thread TheGag96 via Digitalmars-d-learn
Hi guys! I had this homework assignment for data structures that has a pretty easy solution in C++. Reading input like this... 1 2 3 # $ 4 3 * ! # 20 3 / # $ # 62 # $ 2 3 8 * + # 4 48 4 2 + / # SUM # $ 1 2 3 4 5 # R # @ ...where "@" denotes the end of input is fairly simple in C++: string toke