diff options
author | Kyle K <kylek389@gmail.com> | 2011-11-16 18:45:00 -0600 |
---|---|---|
committer | Kamil Kaminski <kamilkss@gmail.com> | 2011-11-16 18:45:00 -0600 |
commit | 320f1c2347e3270a82b90bf03bf0ea1c48ad4eb2 (patch) | |
tree | 1cc263296c52fa6f34647b12fb1030ef492169a4 | |
parent | 148066fb01fb25bcf50a0614bd545ae5d9d0d64f (diff) | |
download | sandbox-320f1c2347e3270a82b90bf03bf0ea1c48ad4eb2.tar.gz sandbox-320f1c2347e3270a82b90bf03bf0ea1c48ad4eb2.tar.bz2 sandbox-320f1c2347e3270a82b90bf03bf0ea1c48ad4eb2.zip |
add a simple sscanf regexp example
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | regexp.c | 14 |
2 files changed, 15 insertions, 1 deletions
@@ -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); +} + |