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();
        }
    }
}

Reply via email to