From b8b37af1a4371a794cb738cc7b204187ddb039f5 Mon Sep 17 00:00:00 2001 From: Simon Forman Date: Wed, 1 Feb 2023 16:02:19 -0800 Subject: [PATCH] Let's parse. --- implementations/C/.gitignore | 1 + implementations/C/parser.c | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 implementations/C/parser.c diff --git a/implementations/C/.gitignore b/implementations/C/.gitignore index 59a897d..2046ae4 100644 --- a/implementations/C/.gitignore +++ b/implementations/C/.gitignore @@ -1 +1,2 @@ joy +parser diff --git a/implementations/C/parser.c b/implementations/C/parser.c new file mode 100644 index 0000000..324af8d --- /dev/null +++ b/implementations/C/parser.c @@ -0,0 +1,23 @@ +#include +#include +#include + +const char *text = "hi there friend"; +/* 01234567890123456789 + ^ ^ +*/ + +int +main(void) +{ + char *rest; + ptrdiff_t diff; + + rest = strpbrk(text, " []"); + while (NULL != rest) { + diff = rest - text; + text = rest; + printf("%ld\n", diff); + rest = strpbrk(++rest, " []"); + } +}