eof
Ali Çehreli
acehreli at yahoo.com
Tue Jun 25 22:11:23 PDT 2013
On 06/25/2013 09:26 PM, lx wrote:
> I input ctrl+c,the code will terminate
> abnormally.Why this happened?
Ctrl-C appears as SIGINT under POSIX systems. You need to register a
handler for that signal:
import std.stdio;
import std.string;
import core.sys.posix.signal;
bool isDone = false;
extern(C) void mySIGINThandler(int) nothrow @system
{
isDone = true;
}
void main()
{
signal(SIGINT, &mySIGINThandler);
while (true) {
string line = chomp(readln());
if (stdin.eof() || isDone) {
break;
} else {
writefln("Nice line: %s", line);
}
}
}
Ali
More information about the Digitalmars-d-learn
mailing list