diff options
| author | Tyge Løvset <[email protected]> | 2020-10-26 20:25:03 +0100 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2020-10-26 20:25:03 +0100 |
| commit | 0b95e794fe91b69928bb111d66fc973d18de7a1f (patch) | |
| tree | 35843d6e5f17e07a3cbb3f8b59df4965661a35d8 /examples/list.c | |
| parent | 0c64199a35a8901a4969f8c2ce0c0483f184732c (diff) | |
| download | STC-modified-0b95e794fe91b69928bb111d66fc973d18de7a1f.tar.gz STC-modified-0b95e794fe91b69928bb111d66fc973d18de7a1f.zip | |
Updates examples using cfmt.h c_print().
Diffstat (limited to 'examples/list.c')
| -rw-r--r-- | examples/list.c | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/examples/list.c b/examples/list.c index 2cc433c6..84a13bf5 100644 --- a/examples/list.c +++ b/examples/list.c @@ -1,7 +1,8 @@ -#include <stdio.h>
#include <time.h>
#include <stc/clist.h>
#include <stc/crandom.h>
+#include <stc/cfmt.h>
+
using_clist(fx, double);
int main() {
@@ -15,26 +16,26 @@ int main() { c_forrange (i, int, n)
clist_fx_push_back(&list, crand_uniform_f64(&eng, &dist)), ++m;
double sum = 0.0;
- printf("sumarize %d:\n", m);
+ c_print(1, "sumarize {}:\n", m);
c_foreach (i, clist_fx, list)
sum += *i.val;
- printf("sum %f\n\n", sum);
+ c_print(1, "sum {}\n\n", sum);
k = 0;
c_foreach (i, clist_fx, list)
- if (++k <= 10) printf("%8d: %10f\n", k, *i.val); else break;
+ if (++k <= 10) c_print(1, "{:3}: {:16.6f}\n", k, *i.val); else break;
puts("sort");
clist_fx_sort(&list); // mergesort O(n*log n)
puts("sorted");
k = 0;
c_foreach (i, clist_fx, list)
- if (++k <= 10) printf("%8d: %10f\n", k, *i.val); else break;
+ if (++k <= 10) c_print(1, "{:3}: {:16.6f}\n", k, *i.val); else break;
puts("");
clist_fx_clear(&list);
c_push_items(&list, clist_fx, {10, 20, 30, 40, 30, 50});
- c_foreach (i, clist_fx, list) printf(" %g", *i.val);
+ c_foreach (i, clist_fx, list) c_print(1, " {}", *i.val);
puts("");
int removed = clist_fx_remove(&list, 30);
@@ -42,13 +43,13 @@ int main() { clist_fx_push_back(&list, 500);
clist_fx_push_front(&list, 1964);
clist_fx_iter_t it = clist_fx_before_begin(&list);
- printf("Full: ");
+ c_print(1, "Full: ");
c_foreach (i, clist_fx, list)
- printf(" %g", *i.val);
+ c_print(1, " {}", *i.val);
for (int i=0; i<4; ++i) clist_fx_next(&it);
- printf("\nSubs: ");
+ c_print(1, "\nSubs: ");
c_foreach (i, clist_fx, it, clist_fx_end(&list))
- printf(" %g", *i.val);
+ c_print(1, " {}", *i.val);
puts("");
clist_fx_del(&list);
}
\ No newline at end of file |
