blob: 0f840a90af8f9716c5eda5ba41d0b262ae4352b2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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;
}
|