From 996286ceea95b8e7ee5a6acd9fa79875ba381f16 Mon Sep 17 00:00:00 2001 From: Tyge Løvset Date: Tue, 30 Mar 2021 23:42:03 +0200 Subject: Moved cset and csset definitions to cset.h and csset.h. Updated docs. --- examples/demos.c | 1 + examples/phonebook.c | 59 ++++++++++++++++++++++++++-------------------------- 2 files changed, 31 insertions(+), 29 deletions(-) (limited to 'examples') diff --git a/examples/demos.c b/examples/demos.c index 9d7f894c..d8228b4e 100644 --- a/examples/demos.c +++ b/examples/demos.c @@ -1,6 +1,7 @@ #include #include #include +#include #include #include diff --git a/examples/phonebook.c b/examples/phonebook.c index 6b2ec687..72ce11f2 100644 --- a/examples/phonebook.c +++ b/examples/phonebook.c @@ -22,6 +22,7 @@ // Program to emulates the phone book. #include +#include #include #include @@ -30,48 +31,48 @@ using_cset_str(); void print_phone_book(cmap_str phone_book) { - c_foreach (i, cmap_str, phone_book) - printf("%s\t- %s\n", i.ref->first.str, i.ref->second.str); + c_foreach (i, cmap_str, phone_book) + printf("%s\t- %s\n", i.ref->first.str, i.ref->second.str); } int main(int argc, char **argv) { - c_static_assert(3 == 3, "hello"); + c_static_assert(3 == 3, "hello"); - c_init (cset_str, names, {"Hello", "Cool", "True"}); - c_foreach (i, cset_str, names) printf("set: %s\n", i.ref->str); + c_init (cset_str, names, {"Hello", "Cool", "True"}); + c_foreach (i, cset_str, names) printf("set: %s\n", i.ref->str); - bool erased; - c_init (cmap_str, phone_book, { - {"Lilia Friedman", "(892) 670-4739"}, - {"Tariq Beltran", "(489) 600-7575"}, - {"Laiba Juarez", "(303) 885-5692"}, - {"Elliott Mooney", "(945) 616-4482"}, - }); + bool erased; + c_init (cmap_str, phone_book, { + {"Lilia Friedman", "(892) 670-4739"}, + {"Tariq Beltran", "(489) 600-7575"}, + {"Laiba Juarez", "(303) 885-5692"}, + {"Elliott Mooney", "(945) 616-4482"}, + }); - printf("Phone book:\n"); - print_phone_book(phone_book); + printf("Phone book:\n"); + print_phone_book(phone_book); - cmap_str_emplace(&phone_book, "Zak Byers", "(551) 396-1880"); - cmap_str_emplace(&phone_book, "Zak Byers", "(551) 396-1990"); + cmap_str_emplace(&phone_book, "Zak Byers", "(551) 396-1880"); + cmap_str_emplace(&phone_book, "Zak Byers", "(551) 396-1990"); - printf("\nPhone book after adding Zak Byers:\n"); - print_phone_book(phone_book); + printf("\nPhone book after adding Zak Byers:\n"); + print_phone_book(phone_book); - if (cmap_str_find(&phone_book, "Tariq Beltran").ref != NULL) - printf("\nTariq Beltran is in phone book\n"); + if (cmap_str_find(&phone_book, "Tariq Beltran").ref != NULL) + printf("\nTariq Beltran is in phone book\n"); - erased = cmap_str_erase(&phone_book, "Tariq Beltran"); - erased = cmap_str_erase(&phone_book, "Elliott Mooney"); + erased = cmap_str_erase(&phone_book, "Tariq Beltran"); + erased = cmap_str_erase(&phone_book, "Elliott Mooney"); - printf("\nPhone book after erasing Tariq and Elliott:\n"); - print_phone_book(phone_book); + printf("\nPhone book after erasing Tariq and Elliott:\n"); + print_phone_book(phone_book); - cmap_str_emplace_or_assign(&phone_book, "Zak Byers", "(555) 396-188"); + cmap_str_emplace_or_assign(&phone_book, "Zak Byers", "(555) 396-188"); - printf("\nPhone book after update phone of Zak Byers:\n"); - print_phone_book(phone_book); + printf("\nPhone book after update phone of Zak Byers:\n"); + print_phone_book(phone_book); - cmap_str_del(&phone_book); - puts("done"); + cmap_str_del(&phone_book); + puts("done"); } \ No newline at end of file -- cgit v1.2.3