From ae032cb11e32f08258dd78c23e7624663cd25ef6 Mon Sep 17 00:00:00 2001 From: Tyge Løvset Date: Tue, 1 Dec 2020 21:45:19 +0100 Subject: Added some examples. --- docs/cvec_api.md | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'docs/cvec_api.md') diff --git a/docs/cvec_api.md b/docs/cvec_api.md index 996cdb16..1a51470e 100644 --- a/docs/cvec_api.md +++ b/docs/cvec_api.md @@ -107,3 +107,35 @@ cvec_X_iter_t cvec_X_end(const cvec_X* self); void cvec_X_next(cvec_X_iter_t* it); cvec_X_value_t* cvec_X_itval(cvec_X_iter_t it); ``` + +## Example +```c +#include +#include +using_cvec(i, int); + +int main() +{ + // Create a vector containing integers + cvec_i v = cvec_inits; + c_push_items(&v, cvec_i, {7, 5, 16, 8}); + + // Add two more integers to vector + cvec_i_push_back(&v, 25); + cvec_i_push_back(&v, 13); + + // Iterate and print values of vector + c_foreach (n, cvec_i, v) { + printf("%d\n", *n.val); + } +} +``` +Output: +``` +7 +5 +16 +8 +25 +13 +``` \ No newline at end of file -- cgit v1.2.3