diff options
| author | Tyge Løvset <[email protected]> | 2020-12-08 10:01:21 +0100 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2020-12-08 10:01:21 +0100 |
| commit | 3c00d164e02342d6c36f69ee0faa105ebb3b6494 (patch) | |
| tree | c23b1d674ea6ec31863c7f131ab5820e516a615a /examples | |
| parent | 5d7bac2f83774e24fd311780a1054dc901753f2e (diff) | |
| download | STC-modified-3c00d164e02342d6c36f69ee0faa105ebb3b6494.tar.gz STC-modified-3c00d164e02342d6c36f69ee0faa105ebb3b6494.zip | |
- Added clone() to cvec and clist
- Renamed cstr_erase(s, pos, n) to cstr_erase_at(s, pos, n)
- Changed cvec_erase_at(v, pos) to cvec_erase_at(v, pos, n).
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/demos.c | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/examples/demos.c b/examples/demos.c index 7e8ef094..0355d32f 100644 --- a/examples/demos.c +++ b/examples/demos.c @@ -14,7 +14,7 @@ void stringdemo1() cstr_insert(&cs, 3, "-two");
printf("%s.\n", cs.str);
- cstr_erase(&cs, 7, 5); // -nine
+ cstr_erase_at(&cs, 7, 5); // -nine
printf("%s.\n", cs.str);
cstr_replace(&cs, cstr_find(cs, "seven"), 5, "four");
@@ -41,14 +41,17 @@ void vectordemo1() printf("\nVECTORDEMO1\n");
cvec_ix bignums = cvec_inits; // = (cvec_ix) cvec_inits; if initializing after declaration.
cvec_ix_reserve(&bignums, 100);
- for (size_t i = 0; i<=100; ++i)
- cvec_ix_push_back(&bignums, i * i * i);
+ for (size_t i = 10; i <= 100; i += 10)
+ cvec_ix_push_back(&bignums, i * i);
- printf("erase - %d: %zu\n", 100, bignums.data[100]);
- cvec_ix_pop_back(&bignums); // erase the last
+ printf("erase - %d: %zu\n", 3, bignums.data[3]);
+ cvec_ix_erase_at(&bignums, 3, 1); // erase index 3
+
+ cvec_ix_pop_back(&bignums); // erase the last
+ cvec_ix_erase_at(&bignums, 0, 1); // erase the first
for (size_t i = 0; i < cvec_size(bignums); ++i) {
- if (i >= 90) printf("%zu: %zu\n", i, bignums.data[i]);
+ printf("%zu: %zu\n", i, bignums.data[i]);
}
cvec_ix_del(&bignums);
}
|
