Input interrupt

helxi via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun May 28 15:07:12 PDT 2017


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



More information about the Digitalmars-d-learn mailing list