/* Copyright (c) 2001-2009 by SoftIntegration, Inc. All Rights Reserved */
/* This is an example of the function wcstok(wchar_t*, const wchar_t*,
                                                 wchar_t**).  This pulls out 
   the tokens from a given string. There is a difference between the number
   of arguments depending on where you compile.  Portability difference
   between HP and Sun.
*/
#include <wchar.h>
#include <stdlib.h>

int main() { 
    char *line, *line2; 
    wchar_t str1[100], str2[100];        
    wchar_t *endptr = NULL;
    wchar_t *token;
    int len1, len2;

    line = "hello goodbye now";
    line2 = " ";
    len1 = strlen(line);
    len2 = strlen(line2);
    mbstowcs(str1, line, len1);
    mbstowcs(str2, line2, len2);
    fputs("Original string: ", stdout);
    fputws(str1, stdout); fputs("\n", stdout);  
    for (token = wcstok(str1, str2, &endptr);
         token != NULL; token= wcstok(NULL, str2, &endptr)) {
      fputs("token = ", stdout); fputws(token, stdout); fputs("\n", stdout);
   }
}

