summaryrefslogtreecommitdiff
path: root/example.c
diff options
context:
space:
mode:
Diffstat (limited to 'example.c')
-rw-r--r--example.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/example.c b/example.c
new file mode 100644
index 0000000..0f840a9
--- /dev/null
+++ b/example.c
@@ -0,0 +1,30 @@
+/*
+ * A small example for using dynstr.
+ *
+ * This does not get built or installed by the build system.
+ */
+
+#include <dynstr.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+
+int main(void)
+{
+ Dynstr *pattern = dynstr_new_from_cstring("needle");
+ for (;;) {
+ Dynstr *line = dynstr_freadline(stdin);
+ if (line == NULL) {
+ perror("reading from stdin");
+ return EXIT_FAILURE;
+ }
+ if (dynstr_is_empty(line)) {
+ dynstr_free(line);
+ break;
+ }
+ if (dynstr_first_string(line, 0, pattern) != DYNSTR_NOT_FOUND)
+ dynstr_fwrite(stdout, line);
+ dynstr_free(line);
+ }
+ return 0;
+}