// filename:c2011-K-3-9-2-3-1-ex.c // original examples and/or notes: // (c) ISO/IEC JTC1 SC22 WG14 N1570, April 12, 2011 // C2011 K.3.9.2.3.1 The wcstok_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 #define __STDC_WANT_LIB_EXT1__ 1 #include #include #include #include #include #include #include //wchar_t *wcstok_s( //wchar_t *strToken, //const wchar_t *strDelimit, // wchar_t**context //); //wchar_t *wcstok_s(wchar_t * restrict ,rsize_t * restrict ,const wchar_t * restrict ,wchar_t ** restrict ); //wchar_t *wcstok_s(wchar_t * _RESTRICT __s1, rsize_t * _RESTRICT __s1max, const wchar_t * _RESTRICT __s2, wchar_t ** _RESTRICT __ptr); int main(void) { static wchar_t str1[] = L"?a???b,,,#c"; static wchar_t str2[] = L"\t \t"; wchar_t *t, *ptr1, *ptr2; rsize_t max1 = wcslen(str1)+1; rsize_t max2 = wcslen(str2)+1; t = wcstok_s(str1, &max1, "?", &ptr1); // t points to the token "a" wprintf(L"%ls",t); t = wcstok_s(NULL, &max1, ",", &ptr1); // t points to the token "??b" wprintf(L"%ls",t); t = wcstok_s(str2, &max2, " \t", &ptr2); // t is a null pointer wprintf(L"%ls",t); t = wcstok_s(NULL, &max1, "#,", &ptr1); // t points to the token "c" wprintf(L"%ls",t); t = wcstok_s(NULL, &max1, "?", &ptr1); // t is a null pointer wprintf(L"%ls",t); return printf("K.3.9.2.3.1 The wcstok_s function \n" ); } // output may be