summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2021-09-24 11:23:09 +0200
committerTyge Løvset <[email protected]>2021-09-24 11:23:09 +0200
commitcee6a7b347daaa94289f0ae71e25f4fd8b861f6a (patch)
tree7f7224469a8b78684e963aa324044364c09afd4a
parent4495d97f43d3d5730828064bbf2590bdb7699e79 (diff)
downloadSTC-modified-cee6a7b347daaa94289f0ae71e25f4fd8b861f6a.tar.gz
STC-modified-cee6a7b347daaa94289f0ae71e25f4fd8b861f6a.zip
Another define fix in template.h. Added 2d string example in new_arr.c
-rw-r--r--examples/new_arr.c50
-rw-r--r--include/stc/template.h2
2 files changed, 34 insertions, 18 deletions
diff --git a/examples/new_arr.c b/examples/new_arr.c
index fef2ab01..dc597e4a 100644
--- a/examples/new_arr.c
+++ b/examples/new_arr.c
@@ -1,4 +1,5 @@
#include <stdio.h>
+#include <stc/cstr.h>
#define i_val int
#include <stc/carr2.h>
@@ -6,40 +7,55 @@
#define i_val int
#include <stc/carr3.h>
+#define i_val_str
+#include <stc/carr2.h>
+
int main()
{
int w = 7, h = 5, d = 3;
- c_autovar (carr2_int image = carr2_int_init(w, h), carr2_int_del(&image))
+ c_autovar (carr2_int volume = carr2_int_init(w, h),
+ carr2_int_del(&volume))
{
- int *dat = carr2_int_data(&image);
- for (size_t i = 0; i < carr2_int_size(image); ++i)
+ int *dat = carr2_int_data(&volume);
+ for (size_t i = 0; i < carr2_int_size(volume); ++i)
dat[i] = i;
- for (size_t x = 0; x < image.xdim; ++x)
- for (size_t y = 0; y < image.ydim; ++y)
- printf(" %d", image.data[x][y]);
+ for (size_t x = 0; x < volume.xdim; ++x)
+ for (size_t y = 0; y < volume.ydim; ++y)
+ printf(" %d", volume.data[x][y]);
puts("");
- c_foreach (i, carr2_int, image)
+ c_foreach (i, carr2_int, volume)
printf(" %d", *i.ref);
+ puts("\n");
}
- puts("\n");
- c_autovar (carr3_int image = carr3_int_init(w, h, d), carr3_int_del(&image))
+ c_autovar (carr3_int volume = carr3_int_init(w, h, d),
+ carr3_int_del(&volume))
{
- int *dat = carr3_int_data(&image);
- for (size_t i = 0; i < carr3_int_size(image); ++i)
+ int *dat = carr3_int_data(&volume);
+ for (size_t i = 0; i < carr3_int_size(volume); ++i)
dat[i] = i;
- for (size_t x = 0; x < image.xdim; ++x)
- for (size_t y = 0; y < image.ydim; ++y)
- for (size_t z = 0; z < image.zdim; ++z)
- printf(" %d", image.data[x][y][z]);
+ for (size_t x = 0; x < volume.xdim; ++x)
+ for (size_t y = 0; y < volume.ydim; ++y)
+ for (size_t z = 0; z < volume.zdim; ++z)
+ printf(" %d", volume.data[x][y][z]);
puts("");
- c_foreach (i, carr3_int, image)
+ c_foreach (i, carr3_int, volume)
printf(" %d", *i.ref);
+ puts("");
+ }
+
+ c_autovar (carr2_str text2d = carr2_str_with_values(h, d, cstr_init()),
+ carr2_str_del(&text2d))
+ {
+ cstr_assign(&text2d.data[2][1], "hello");
+ cstr_assign(&text2d.data[4][0], "world");
+
+ c_foreach (i, carr2_str, text2d)
+ printf("line: %s\n", i.ref->str);
}
- puts("");
}
diff --git a/include/stc/template.h b/include/stc/template.h
index 9b27dc9e..6b7d1067 100644
--- a/include/stc/template.h
+++ b/include/stc/template.h
@@ -113,7 +113,7 @@
#endif
#ifdef i_key
- #ifndef i_val
+ #ifdef i_isset
#define i_val i_key
#endif
#ifndef i_tag