// filename:c2011-K-3-7-3-1-ex.c // original examples and/or notes: // (c) ISO/IEC JTC1 SC22 WG14 N1570, April 12, 2011 // C2011 K.3.7.3.1 The strtok_s function // compile and output mechanism: // (c) Ogawa Kiyoshi, kaizen@gifu-u.ac.jp, December.29, 2013 // compile errors and/or wornings: // (c) Apple LLVM version 4.2 (clang-425.0.27) (based on LLVM 3.2svn) // Target: x86_64-apple-darwin11.4.2 //Thread model: posix // (c) LLVM 2003-2009 University of Illinois at Urbana-Champaign. // Example 1 #define __STDC_WANT_LIB_EXT1__ 1 #include #include int main(void) { /* ... */ static char str1[] = "?a???b,,,#c"; static char str2[] = "\t \t"; char *t, *ptr1, *ptr2; rsize_t max1 = sizeof (str1); rsize_t max2 = sizeof (str2); t = strtok_s(str1, &max1, "?", &ptr1); // t points to the token "a" printf("%s", t); t = strtok_s(NULL, &max1, ",", &ptr1); // t points to the token "??b" printf("%s", t); t = strtok_s(str2, &max2, " \t", &ptr2); // t is a null pointer printf("%s", t); t = strtok_s(NULL, &max1, "#,", &ptr1); // t points to the token "c" printf("%s", t); t = strtok_s(NULL, &max1, "?", &ptr1); // t is a null pointer return printf("K.3.7.1.4 The strncpy_s function %s \n",t ); } // output may be