/************************************************************************ * * * Copyright Digital Equipment Corporation 1998. All rights reserved. * * * * Restricted Rights: Use, duplication, or disclosure by the U.S. * * Government is subject to restrictions as set forth in subparagraph * * (c) (1) (ii) of DFARS 252.227-7013, or in FAR 52.227-19, or in FAR * * 52.227-14 Alt. III, as applicable. * * * * This software is proprietary to and embodies the confidential * * technology of Digital Equipment Corporation. Possession, use, or * * copying of this software and media is authorized only pursuant to a * * valid written license from Digital or an authorized sublicensor. * * * ************************************************************************/ #include #include #include #include #include /* * This test calls wcstoul() to convert a string to an unsigned long * integer. The resulting integer and any characters that could not * be converted are output. */ #define MAX_STRING 128 main() { int base = 10, errno; char *input_string = "1234.56"; wchar_t string_array[MAX_STRING], *ptr; size_t size; unsigned long int val; printf("base = [%d]\n", base); printf("String to convert = %s\n", input_string); if ((size = mbstowcs(string_array, input_string, MAX_STRING)) == (size_t) - 1) { perror("mbstowcs"); exit(EXIT_FAILURE); } printf("wchar_t string is = [%S]\n", string_array); errno = 0; val = wcstoul(string_array, &ptr, base); if (errno == 0) { printf("returned unsigned long int from wcstoul = [%u]\n", val); printf("wide char terminating scan(ptr) = [%S]\n\n", ptr); } if (errno == ERANGE) { perror("error value is :"); printf("ULONG_MAX = [%u]\n", ULONG_MAX); printf("wcstoul failed, val = [%d]\n\n", val); } }