Date: Sun, 01 May 2011 16:45:14 +0200 From: Martin =?ISO-8859-1?B?TfZsbGVy?= <moeller.akt@googlemail.com> To: Daniel O'Connor <doconnor@gsoft.com.au> Cc: freebsd-hackers@freebsd.org Subject: Re: [LIBC] Modfied Version of sscanf Message-ID: <C9E33E9A.379%moeller.akt@googlemail.com> In-Reply-To: <6ACFC545-73B5-49FA-A97F-BC500F9AFE40@gsoft.com.au>
next in thread | previous in thread | raw e-mail | index | archive | help
Am 01.05.11 00:53 schrieb "Daniel O'Connor" unter <doconnor@gsoft.com.au>: Thanks for your reply. Ok, another example. I try to parse a request, coming from a client in the form: GET <resource> HTTP/1.1. It is expected that <resource> can contain space characters (even if its not the case in reality). How would you do that with sscanf ? With regards, Martin >=20 > On 01/05/2011, at 2:14, Martin M=F6ller wrote: >> outputs total garbage on my FreeBSD-7.0-RELEASE #0 amd64. >> Is there already a way to do this or should we release a new version of >> sscanf, e.g. called sscanfWS. >>=20 >> This modified version would output: Test 2->Test 3. >=20 > I think it does what it should.. %s is supposed to stop at whitespace. >=20 > You probably really want.. >=20 > #include <stdio.h> > #include <stdlib.h> > #include <sys/types.h> >=20 > int > main(int argc, char **argv) { > char name [20], value [20]; > int i; >=20 > i =3D sscanf("Test 2->Test 3", "%[^-]->%[^-]", name, value); > printf("%d %s->%s\n", i, name, value); >=20 > exit(0); > } >=20 > -- > Daniel O'Connor software and network engineer > for Genesis Software - http://www.gsoft.com.au > "The nice thing about standards is that there > are so many of them to choose from." > -- Andrew Tanenbaum > GPG Fingerprint - 5596 B766 97C0 0E94 4347 295E E593 DC20 7B3F CE8C >=20 >=20 >=20 >=20 >=20 >=20
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?C9E33E9A.379%moeller.akt>