summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKyle K <kylek389@gmail.com>2011-11-16 18:45:00 -0600
committerKamil Kaminski <kamilkss@gmail.com>2011-11-16 18:45:00 -0600
commit320f1c2347e3270a82b90bf03bf0ea1c48ad4eb2 (patch)
tree1cc263296c52fa6f34647b12fb1030ef492169a4
parent148066fb01fb25bcf50a0614bd545ae5d9d0d64f (diff)
downloadsandbox-320f1c2347e3270a82b90bf03bf0ea1c48ad4eb2.tar.gz
sandbox-320f1c2347e3270a82b90bf03bf0ea1c48ad4eb2.tar.bz2
sandbox-320f1c2347e3270a82b90bf03bf0ea1c48ad4eb2.zip
add a simple sscanf regexp example
-rw-r--r--Makefile2
-rw-r--r--regexp.c14
2 files changed, 15 insertions, 1 deletions
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);
+}
+