From 320f1c2347e3270a82b90bf03bf0ea1c48ad4eb2 Mon Sep 17 00:00:00 2001 From: Kyle K <kylek389@gmail.com> Date: Wed, 16 Nov 2011 18:45:00 -0600 Subject: add a simple sscanf regexp example --- Makefile | 2 +- regexp.c | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 regexp.c diff --git a/Makefile b/Makefile index 9ff95e4..07d4312 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ BINS = ascii class depipe_strings dup fpipe pipe realloc strpbrk strsep \ tokenizer getopt prime_mask linked_list pi_bbp string_tokenizer \ - tcpserver tcpclient + tcpserver tcpclient regexp CC = gcc CFLAGS = -Wall -std=gnu99 -pedantic DBGFLAGS = -g -O0 diff --git a/regexp.c b/regexp.c new file mode 100644 index 0000000..ffaa1fc --- /dev/null +++ b/regexp.c @@ -0,0 +1,14 @@ +#include <stdio.h> + +int main(int argc, char **argv) +{ + char name[50 + 1], email[50 + 1]; + char *string = "\"Bro Brotato\" <bro@hax.org>"; + + /* i'm telling sscanf how string looks, %[] is the regexp */ + sscanf(string, "\"%50[^\"<]\" <%50[^>]", name, email); + + printf("name: \"%s\"\n", name); + printf("email: \"%s\"\n", email); +} + -- cgit v1.2.3