diff options
author | Lars Wirzenius <liw@liw.fi> | 2011-03-05 15:48:04 +0000 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2011-03-05 15:48:04 +0000 |
commit | b07e8ee6cac9cfd17d786cd6f3e39a3ca66f00c3 (patch) | |
tree | bf065214bccd700d24a22c59b0291fa0d3fd7986 | |
parent | 460b15acd6b56d0dc11d83d2250ebc14a44ee8ee (diff) | |
download | dynstr-b07e8ee6cac9cfd17d786cd6f3e39a3ca66f00c3.tar.gz |
Add example.
-rw-r--r-- | example.c | 30 |
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; +} |