1 // RUNNABLE_PHOBOS_TEST
3 // EXECUTE_ARGS: runnable/wc2.d
7 extern(C) int printf(const char*, ...);
9 int main (string[] args)
14 int[string] dictionary;
16 printf(" lines words bytes file\n");
17 foreach (string arg; args[1 .. args.length])
20 int w_cnt, l_cnt, c_cnt;
24 input = cast(string)std.file.read(arg);
26 for (int j = 0; j < input.length; j++)
32 if (c >= '0' && c <= '9')
35 else if (c >= 'a' && c <= 'z' ||
46 { string word = input[wstart .. j];
54 { string w = input[wstart .. input.length];
57 printf("%8u%8u%8u %.*s\n", l_cnt, w_cnt, c_cnt, cast(int)arg.length, arg.ptr);
65 printf("--------------------------------------\n%8u%8u%8u total",
66 l_total, w_total, c_total);
69 printf("--------------------------------------\n");
70 foreach (string word1; dictionary.keys)
72 printf("%3d %.*s\n", dictionary[word1], cast(int)word1.length, word1.ptr);