forked from dlang/dmd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwc.d
54 lines (43 loc) · 1016 Bytes
/
wc.d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import std.stdio;
import std.file;
import std.conv;
int main(string[] args)
{
int w_total;
int l_total;
int c_total;
writeln(" lines words bytes file");
foreach (arg; args[1 .. $])
{
string input;
int w_cnt, l_cnt, c_cnt;
int inword;
input = to!string(std.file.read(arg));
foreach (char c; input)
{
if (c == '\n')
++l_cnt;
if (c != ' ')
{
if (!inword)
{
inword = 1;
++w_cnt;
}
}
else
inword = 0;
++c_cnt;
}
writefln("%8s%8s%8s %s\n", l_cnt, w_cnt, c_cnt, arg);
l_total += l_cnt;
w_total += w_cnt;
c_total += c_cnt;
}
if (args.length > 2)
{
writefln("--------------------------------------\n%8s%8s%8s total",
l_total, w_total, c_total);
}
return 0;
}