digitalmars.D.learn - Input interrupt
- helxi (42/42) May 28 2017 Hello, I just wrote a mock-up of Unix's $cat. However unlike the
- Adam D. Ruppe (12/14) May 28 2017 The readln docs for D say it returns null on end of file. The
- helxi (4/18) May 28 2017 Oh yes, fantastic,
Hello, I just wrote a mock-up of Unix's $cat. However unlike the
actual $cat, when input interrupt (Cntrl+D) is pressed the
following program does not stop.
So I tried using C's EOF but the types aren't compatible since
EOF is probably aliased to -1
//...
if (args.length < 2)
{
string input = readln();
while (input != EOF)
{
input.write();
}
}
//...
Tips?
Here is the full program:
import std.stdio;
import std.file;
void main(string[] args)
{
if (args.length < 2)
{
string input = readln();
while (input != EOF)
{
input.write();
}
}
else
{
foreach (path; args[1..$])
{
auto current_file = File(path, "r");
while (!(current_file.eof()))
{
current_file.readln().write();
}
current_file.close();
}
}
}
May 28 2017
On Sunday, 28 May 2017 at 22:07:12 UTC, helxi wrote:So I tried using C's EOF but the types aren't compatible since EOF is probably aliased to -1The readln docs for D say it returns null on end of file. The example given is: import std.stdio; void main() { string line; while ((line = readln()) !is null) write(line); } http://dpldocs.info/experimental-docs/std.stdio.readln.1.html I would try that.
May 28 2017
On Sunday, 28 May 2017 at 22:14:46 UTC, Adam D. Ruppe wrote:On Sunday, 28 May 2017 at 22:07:12 UTC, helxi wrote:Oh yes, fantastic, I also seem to have forgotten EOF was meant to compare chars, not strings.So I tried using C's EOF but the types aren't compatible since EOF is probably aliased to -1The readln docs for D say it returns null on end of file. The example given is: import std.stdio; void main() { string line; while ((line = readln()) !is null) write(line); } http://dpldocs.info/experimental-docs/std.stdio.readln.1.html I would try that.
May 28 2017








helxi <brucewayneshit gmail.com>