summaryrefslogtreecommitdiffhomepage
path: root/examples
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2021-03-30 23:42:03 +0200
committerTyge Løvset <[email protected]>2021-03-30 23:42:03 +0200
commit996286ceea95b8e7ee5a6acd9fa79875ba381f16 (patch)
tree5a07821cc76efc354201926a1352ee10199fb203 /examples
parentf352471e79cbdad71409ad5a679d03cab9634d43 (diff)
downloadSTC-modified-996286ceea95b8e7ee5a6acd9fa79875ba381f16.tar.gz
STC-modified-996286ceea95b8e7ee5a6acd9fa79875ba381f16.zip
Moved cset and csset definitions to cset.h and csset.h. Updated docs.
Diffstat (limited to 'examples')
-rw-r--r--examples/demos.c1
-rw-r--r--examples/phonebook.c59
2 files changed, 31 insertions, 29 deletions
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 <stc/cvec.h>
#include <stc/clist.h>
#include <stc/carray.h>
+#include <stc/cset.h>
#include <stc/cmap.h>
#include <stc/cstr.h>
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 <stdio.h>
+#include <stc/cset.h>
#include <stc/cmap.h>
#include <stc/cstr.h>
@@ -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