From 172df98c0d9ca58afe0eb846f1edd2c888ffe273 Mon Sep 17 00:00:00 2001 From: Patrick Pelissier Date: Thu, 6 Jul 2017 11:49:07 +0200 Subject: [PATCH] Add new example based on set and word counts. --- example/ex-dict04.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 example/ex-dict04.c diff --git a/example/ex-dict04.c b/example/ex-dict04.c new file mode 100644 index 00000000..6ab3965a --- /dev/null +++ b/example/ex-dict04.c @@ -0,0 +1,18 @@ +#include +#include "m-string.h" +#include "m-dict.h" + +/* program that reads text from standard-input, + and prints the total number of distinct words found in the text. +*/ +DICT_SET_DEF2(str, string_t, STRING_OPLIST) + +int main(void) +{ + M_LET(word, STRING_OPLIST) + M_LET(wordcount, DICT_SET_OPLIST(str, STRING_OPLIST)) { + while (string_fget_word(word, " \t\n,.!;:?", stdin)) + dict_str_set_at(wordcount, word); + printf ("Words: %lu\n", dict_str_size(wordcount)); + } +}