summaryrefslogtreecommitdiffhomepage
path: root/misc/examples/coread.c
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2023-03-01 14:36:38 +0100
committerTyge Løvset <[email protected]>2023-03-01 14:36:38 +0100
commit78a7e85535fd02e643bf98103223d4218e80133f (patch)
treebe22b46aaa7ac48b29125863d27db591cf12dcdf /misc/examples/coread.c
parent8fdcfbf621b5e8c1298a89579594db0817adce26 (diff)
downloadSTC-modified-78a7e85535fd02e643bf98103223d4218e80133f.tar.gz
STC-modified-78a7e85535fd02e643bf98103223d4218e80133f.zip
Moved algorithm examples to algo folder.
Diffstat (limited to 'misc/examples/coread.c')
-rw-r--r--misc/examples/coread.c36
1 files changed, 0 insertions, 36 deletions
diff --git a/misc/examples/coread.c b/misc/examples/coread.c
deleted file mode 100644
index c5f85e08..00000000
--- a/misc/examples/coread.c
+++ /dev/null
@@ -1,36 +0,0 @@
-#include <stc/cstr.h>
-#include <stc/algo/coroutine.h>
-#include <errno.h>
-
-// Read file line by line using coroutines:
-
-struct file_nextline {
- const char* filename;
- int cco_state;
- FILE* fp;
- cstr line;
-};
-
-bool file_nextline(struct file_nextline* U)
-{
- cco_begin(U)
- U->fp = fopen(U->filename, "r");
- U->line = cstr_init();
-
- while (cstr_getline(&U->line, U->fp))
- cco_yield(true);
-
- cco_final: // required label.
- printf("finish\n");
- cstr_drop(&U->line);
- fclose(U->fp);
- cco_end(false);
-}
-
-int main(void) {
- struct file_nextline z = {__FILE__};
- int n = 0;
- while (file_nextline(&z)) {
- printf("%3d %s\n", ++n, cstr_str(&z.line));
- }
-}