1: import std.file; 2: import std.stream; 3: import std.string; 4: 5: int main(char args[][]) { 6: File file; 7: char words[][]; 8: uint wordcount[char[]]; 9: uint wordcounttotal; 10: 11: foreach (char filename[]; args[1 .. args.length]) { 12: file = new File(filename); 13: 14: while (!file.eof()) { 15: words = split(file.readLine()); 16: 17: foreach (char word[]; words) { 18: wordcount[word]++; 19: wordcounttotal++; 20: debug { 21: stderr.printf("word=%.*s\n", word); 22: } 23: } 24: } 25: 26: delete file; 27: } 28: 29: foreach (char word[]; wordcount.keys) { 30: stdout.printf("The word \"%.*s\" appears %i times.\n", word, wordcount[word]); 31: } 32: stdout.printf("Total words: %i\n", wordcounttotal); 33: 34: return(0); 35: } wc.d is an implementation of a word counter in D. |