[Assorted-commits] SF.net SVN: assorted: [324] sandbox/trunk/src/c/strings.c
Brought to you by:
yangzhang
From: <yan...@us...> - 2008-02-06 04:34:11
|
Revision: 324 http://assorted.svn.sourceforge.net/assorted/?rev=324&view=rev Author: yangzhang Date: 2008-02-05 20:34:16 -0800 (Tue, 05 Feb 2008) Log Message: ----------- added strsep test Modified Paths: -------------- sandbox/trunk/src/c/strings.c Modified: sandbox/trunk/src/c/strings.c =================================================================== --- sandbox/trunk/src/c/strings.c 2008-02-04 19:35:24 UTC (rev 323) +++ sandbox/trunk/src/c/strings.c 2008-02-06 04:34:16 UTC (rev 324) @@ -1,8 +1,31 @@ #include <string.h> +#include <stdio.h> int main() { - char buf[256] = "asdf"; - int i = strncasecmp(buf, "ASDF", 256); - printf("%d\n", i); - return 0; + { + char buf[256] = "asdf"; + int i = strncasecmp(buf, "ASDF", 256); + // Prints 0, meaning that the strings match. + printf("%d\n", i); + } + + { + char buf[256] = "hello hello hello"; + char *p = buf; + // Prints: + // hello + // 6 + // hello + // 12 + // + // 13 + // hello + // 1662417648 + while (p != NULL) { + printf("%s\n", strsep(&p, " ")); + printf("%d\n", p - buf); + } + } + + return 0; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |