home *** CD-ROM | disk | FTP | other *** search
/ The Developer Connection…ice Driver Kit for OS/2 3 / DEV3-D1.ISO / docs / xpg4.inf (.txt) < prev   
Encoding:
OS/2 Help File  |  1994-02-27  |  120.4 KB  |  5,231 lines

  1.  
  2. ΓòÉΓòÉΓòÉ 1. XPG4 Internationalization (I18N) for OS/2 ΓòÉΓòÉΓòÉ
  3.  
  4. =============================================================
  5. XPG/4 Internationalization For OS/2              January 1994
  6. =============================================================
  7.  
  8.                Copyright IBM Corporation -- 1993, 1994
  9.  
  10.     DISCLAIMER: This package has been made available solely to
  11.     gauge OS/2 Developer interest in XPG/4 Internationalization
  12.     programming model and does not mean that IBM will introduce
  13.     a product based on what is contained in this package.
  14.  
  15.  
  16. ΓòÉΓòÉΓòÉ 1.1. Overview ΓòÉΓòÉΓòÉ
  17.  
  18. XPG4 Internationalization (I18N) consists of a set of APIs, commands and locale 
  19. .dll's.  This SDF contains lists of these items as well as the programming 
  20. guidelines for using them effectively. 
  21.  
  22. The XPG4 library is based on a locale model, where the world is divided up into 
  23. a collection of locales. A given country may have one or more locales depending 
  24. on its cultural diversity. A locale is a combination of language and country 
  25. monetary, time and character sorting conventions. The best example of the 
  26. locale model is Switzerland which has German, Italian, and Swiss locales, since 
  27. it is a trilingual country. 
  28. Recommended Reading 
  29.  
  30. The Library of NLS recommends the following books: 
  31.  
  32.  GG24-3850   ITSC AIX 3.2 Natl Language Support 
  33.  
  34.  SC23-2431   Internationalization of AIX Software: A Programmer's Guide 
  35.  
  36.  XOPEN       XPG/4 CAE Specification, Issue 4 
  37.  
  38.  Use of SETLOCALE 
  39.  
  40.  By design, an application program initially starts up in the default C locale. 
  41.  Upon calling the setlocale routine, the program's locale is determined by 
  42.  either the LANG, and LC_* environment variables, or directly by the 2nd 
  43.  argument to setlocale. 
  44.  
  45.   #include <wchar.h>
  46.  
  47.   main() {
  48.  
  49.       // The LC_ALL and LANG environment variables set the program's locale
  50.  
  51.       (void)setlocale(LC_ALL, "");
  52.       }
  53.  
  54.  Setlocale can also be used to query what locale is currently active for a 
  55.  given LC_* value, by providing a NULL 2nd argument. 
  56.  Use of WCHAR_T 
  57.  
  58.  The wchar_t datatype extends the range of the standard char datatype to 16-bit 
  59.  characters. In general programmers only need to use this datatype when direct 
  60.  character manipulation is needed on multi-byte character data. Special 
  61.  functions are provided to convert between multi-byte and wchar strings, (see 
  62.  mbstowcs and wcstombs functions below) and to copy, compare, or search wchar 
  63.  strings (see wcs* functions below). 
  64.  Use of CHAR 
  65.  
  66.  The char datatype is still used in most cases but now it may contain 
  67.  multi-byte characters as defined in the specific locale. A multi-byte 
  68.  character is composed of one or more bytes, with no imbedded null bytes. The 
  69.  standard C str* functions are used to manipulate these kinds of strings. 
  70.  Environment Variables 
  71.  
  72.  The following environment variables are used for internationalization to 
  73.  determine the behavior of the system after calling the setlocale() API.  The 
  74.  variables are set as defaults by the application at boot time in CONFIG.SYS or 
  75.  directly via the SET command. 
  76.  
  77.  LOCPATH         specifies the search path for the localized .dll's including 
  78.                  binary locale files, converters, and message files. 
  79.  
  80.  LANG =value     where value is the file name of the locale .dll, e.g. the 
  81.                  value En_US is American English.  Values are provided in the 
  82.                  "List of locales provided in the library" section. 
  83.  
  84.  NLSPATH         specifies the search path for locating the message catalo 
  85.                  files.  The environment variable is used by the Message 
  86.                  Facility component of the NLS subsystem. 
  87.  Locale values can also be set by the LC_* environment variables. 
  88.  
  89.  LC_ALL          overrides the value of other LC_* environment variables 
  90.  
  91.  LC_COLLATE      determines the character-collation or string-collation rules 
  92.                  governing the behavior of ranges, equivalence classes and 
  93.                  multicharacter collating elements. 
  94.  
  95.  LC_CTYPE        determines character handling rules governing the 
  96.                  interpretation of sequences of bytes of text data characters 
  97.                  (single- byte or multi-byte characters), the classification of 
  98.                  characters (for example, alpha, digit and so on) and the 
  99.                  behavior of character classes. 
  100.  
  101.  LC_MESSAGES     determines the locale (language) for messages and menus.  It 
  102.                  also determines the rules for affirmative and negative 
  103.                  responses according to locale, although such responses are not 
  104.                  recommended by NLS Guidelines or CUA. 
  105.  
  106.  LC_MONETARY     determines the rules governing monetary formatting. 
  107.  
  108.  LC_NUMERIC      determines the rules governing numeric formatting other than 
  109.                  monetary. 
  110.  
  111.  LC_TIME         determines the rules governing date and time formatting. 
  112.  
  113.  The application should use only the LANG, LOCPATH and NLSPATH variables.  A 
  114.  user can override them with the locale environment variables.  The settings 
  115.  are queried for priority level as follows: 
  116.  
  117.    1. If the LC_ALL environment variable is set, the value of the LC_ALL 
  118.       variable is used for all categories. 
  119.  
  120.    2. If the LC_ALL environment variable is not set, the values specified for 
  121.       medium-priority environment variables (LC_COLLATE, LC_CTYPE, LC_MESSAGES, 
  122.       LC_MONETARY, LC_NUMERIC, LC_TIME) are used. 
  123.  
  124.    3. If individual LC_* environment variables are not set, the value of the 
  125.       LANG environment variable specifies the locale for all remaining 
  126.       categories. 
  127.  
  128.    4. If the LANG environment variable is not set, the locale for all remaining 
  129.       categories defaults to the C locale. 
  130.  
  131.  List of locales provided in the library 
  132.  
  133.  Note:  CP/CS means codepage/character set. 
  134.  
  135.  Locale value Language and Territory 
  136.  C           Provides hard links to the English catalogs for those program 
  137.              products that do not provide default message text strings. 
  138.  De_DE       German in Germany (and Austria) 
  139.  En_GB       English in the U.K. 
  140.  En_US       English in the U.S. 
  141.  Es_ES       Spanish in Spain 
  142.  Fr_FR       French in France 
  143.  It_IT       Italian in Italy 
  144.  Jp_JP       Japanese in Japan 
  145.  
  146.  List of OS/2 commands provided: 
  147.  
  148.  gencat          constructs message cat files 
  149.  
  150.  mkcatdefs       constructs message #define .H files 
  151.  
  152.  runcat          script to construct message cat files and associated .H files 
  153.                  (via mkcatdefs + gencat) 
  154.  
  155.  List of functions provided in the library 
  156.  
  157.    1. Runtime Locale Load/Query Function: 
  158.  
  159.  
  160.                 char *setlocale(int, const char *);
  161.  
  162.    2. Messages Catalog Functions: 
  163.  
  164.  
  165.                 nl_catd   catopen(const char *name, int oflag);
  166.                 char     *catgets(nl_catd catd, int setid, int msgid, const char *s);
  167.                 int       catclose(nl_catd catd);
  168.  
  169.    3. File I/O functions: 
  170.  
  171.  
  172.                 wint_t   fgetwc(FILE *stream);
  173.                 wchar_t *fgetws(wchar_t *ws, int n, FILE *stream);
  174.  
  175.                 wint_t   fputwc(wint_t wc, FILE *stream);
  176.                 int      fputws(const wchar_t *ws, FILE *stream);
  177.  
  178.                 wint_t   getwc (FILE *stream);
  179.                 wint_t   putwc(wint_t wc, FILE *stream);
  180.                 wint_t   ungetwc(wint_t wc, FILE *stream);
  181.  
  182.                 wint_t   getwchar(void);
  183.                 wint_t   putwchar(wint_t wc);
  184.  
  185.    4. I/O Conversion Functions: 
  186.  
  187.  
  188.                 iconv_t iconv_open(const char *tocode, const char *fromcode);
  189.  
  190.                 size_t  iconv(iconv_t cd, const char **inbuf, size_t *inbytesleft,
  191.                                                 char **outbuf, size_t *outbytesleft);
  192.  
  193.                 int     iconv_close(iconv_t *cd);
  194.  
  195.    5. Character Attribute testing (Uses locale-based methods): 
  196.  
  197.  
  198.                int isalnum(int c);
  199.                int isalpha(int c);
  200.                int iscntrl(int c);
  201.                int isdigit(int c);
  202.                int isgraph(int c);
  203.                int islower(int c);
  204.                int isprint(int c);
  205.                int ispunct(int c);
  206.                int isspace(int c);
  207.                int isupper(int c);
  208.                int isxdigit(int c);
  209.  
  210.                int toupper(int c);
  211.                int tolower(int c);
  212.  
  213.                int iswalnum(wint_t wc);
  214.                int iswalpha(wint_t wc);
  215.                int iswcntrl(wint_t wc);
  216.                int iswdigit(wint_t wc);
  217.                int iswgraph(wint_t wc);
  218.                int iswlower(wint_t wc);
  219.                int iswprint(wint_t wc);
  220.                int iswpunct(wint_t wc);
  221.                int iswspace(wint_t wc);
  222.                int iswupper(wint_t wc);
  223.                int iswxdigit(wint_t wc);
  224.  
  225.                int iswctype(wint_t wc, wctype_t mask);
  226.  
  227.                wint_t towupper(wint_t wc);
  228.                wint_t towlower(wint_t wc);
  229.  
  230.                wctype_t wctype(const char *charclass);
  231.  
  232.    6. The basic conversion methods for multibyte and wchar_t: 
  233.  
  234.  
  235.                 int    mblen(const char *s, size_t n);
  236.                 size_t mbstowcs(wchar_t *ws, const char *s, size_t n);
  237.                 int    mbtowc(wchar_t *wc, const char *s, size_t n);
  238.                 size_t wcstombs(char *s, const wchar_t *ws, size_t n);
  239.                 int    wcswidth(const wchar_t *ws, size_t n);
  240.                 int    wctomb(char *s, wchar_t wchar);
  241.                 int    wcwidth(wint_t wc);
  242.  
  243.    7. Formatted I/O Functions: 
  244.  
  245.  
  246.                 fscanf/scanf/sscanf with %ws, %wc decoding, and parameter
  247.                                     reordering via the (%n$x) format
  248.  
  249.                 fprintf/printf/sprintf with %ws, %wc encoding, and parameter
  250.                                        reordering via the (%n$x) format
  251.  
  252.    8. Collations: 
  253.  
  254.  
  255.                 int strcoll(const char *s1, const char *s2);
  256.                 size_t strxfrm(char *s1, const char *s2, size_t n);
  257.  
  258.                 int wcscoll(const wchar_t *ws1, const wchar_t *ws2);
  259.                 size_t wcsxfrm(wchar_t *ws1, const wchar_t *ws2, size_t n);
  260.  
  261.    9. Date and Time Formatting: 
  262.  
  263.  
  264.                 size_t strftime(char *s, size_t maxsize, const char *format,
  265.                                 const struct tm *tm);
  266.  
  267.                 size_t strfmon(char *s, size_t maxsize, const char *format, ...);
  268.  
  269.                 char  *strptime(const char *buf, const char *fmt, struct tm *tm);
  270.  
  271.                 size_t wcsftime(wchar_t *wcs, size_t maxsize, const char *format,
  272.                                 const struct tm *tm);
  273.  
  274.                 char *nl_langinfo(nl_item item);
  275.                 struct lconv *localeconv(void);
  276.  
  277.                 long wcstol(const wchar_t *nptr,
  278.                                   wchar_t **endptr, int base);
  279.  
  280.                 unsigned long wcstoul(const wchar_t *nptr,
  281.                                             wchar_t **endptr, int base);
  282.  
  283.   10. Basic String manipulation API for wchar_t data type: 
  284.  
  285.  
  286.                 size_t   wcscspn (const wchar_t *ws1, const wchar_t *ws2);
  287.                 size_t   wcslen  (const wchar_t *ws);
  288.                 wchar_t *wcscat  (wchar_t       *ws1, const wchar_t *ws2);
  289.                 wchar_t *wcscpy  (wchar_t       *ws1, const wchar_t *ws2);
  290.                 int      wcscmp  (const wchar_t *ws1, const wchar_t *ws2);
  291.                 int      wcsncmp (const wchar_t *ws1, const wchar_t *ws2, size_t n);
  292.                 wchar_t *wcspbrk (const wchar_t *ws1, const wchar_t *ws2);
  293.                 wchar_t *wcsncpy (wchar_t       *ws1, const wchar_t *ws2, size_t n);
  294.                 size_t   wcsspn  (const wchar_t *ws1, const wchar_t *ws2);
  295.                 wchar_t *wcschr  (wchar_t       *ws1, wint_t         wc);
  296.                 wchar_t *wcsncat (wchar_t       *ws1, const wchar_t *ws2, size_t n);
  297.                 wchar_t *wcsrchr (wchar_t       *ws1, wint_t         wc);
  298.                 wchar_t *wcstok  (wchar_t       *ws1, const wchar_t *ws2);
  299.                 wchar_t *wcswcs  (const wchar_t *ws1, const wchar_t *ws2);
  300.  
  301.  
  302. ΓòÉΓòÉΓòÉ 2. SetLocale ΓòÉΓòÉΓòÉ
  303.  
  304.  
  305. ΓòÉΓòÉΓòÉ 2.1. SetLocale -- Defines the Program's Locale ΓòÉΓòÉΓòÉ
  306.  
  307.  
  308. Syntax 
  309.  
  310. #include <locale.h>
  311.  
  312. char *setlocale(int category, const char *locale);
  313.  
  314. Description 
  315.  
  316. The setlocale function changes or queries variables, defined in the locale.h 
  317. header file, that indicate location.  The values for category are listed below. 
  318.  
  319.  Category        Purpose 
  320.  
  321.  LC_ALL          Names entire locale of program. 
  322.  
  323.  LC_COLLATE      Affects behavior of the strcoll and strxfrm functions. 
  324.  
  325.  LC_CTYPE        Affects behavior of the character handling functions (See IS* 
  326.                  functions) 
  327.  
  328.  LC_MESSAGES     Affects message information (See CatGets functions) 
  329.  
  330.  LC_MONETARY     Affects monetary information (See strfmon functions) 
  331.  
  332.  LC_NUMERIC      Affects the decimal-point character for the formatted 
  333.                  input/output and string conversion functions, and the 
  334.                  nonmonetary formatting information returned by the localeconv 
  335.                  function. 
  336.  
  337.  LC_TIME         Affects behavior of the strftime function. 
  338.  
  339.  You can set the value of locale to: 
  340.  
  341.  "C"       Default C locale 
  342.  
  343.  ""        Environment defined locale 
  344.  
  345.  "De_DE"   German in Germany 
  346.  
  347.  "En_GB"   English in Great Britain 
  348.  
  349.  "En_US"   English in the United States 
  350.  
  351.  "Es_ES"   Spanish in Spain 
  352.  
  353.  "Fr_FR"   French in France 
  354.  
  355.  "It_IT"   Italian in Italy 
  356.  
  357.  "Jp_JP"   Japanese in Japan 
  358.  
  359.  A locale value of "C" indicates the default C environment.  A locale value of 
  360.  "" tells setlocale to use the default locale for the implementation. 
  361.  
  362.  The setlocale function returns a pointer to the string associated with the 
  363.  specified category for the new locale.  The string can be used on a subsequent 
  364.  call to restore that part of the program's locale. 
  365.  
  366.  Note:  Because the string to which a successful call to setlocale points may 
  367.  be overwritten by subsequent calls to the setlocale function, you should copy 
  368.  the string if you plan to use it later. 
  369.  
  370.  On error, the setlocale function returns NULL and the program's locale is not 
  371.  changed. 
  372.  
  373.  To query the locale, give a NULL as the second parameter.  For example, to 
  374.  query all the categories of your locale, enter the following statement: 
  375.  
  376.  
  377.       char *string = setlocale(LC_ALL, NULL);
  378.  
  379.  
  380.  Related Information 
  381.  
  382.    o  getenv  - Search for Environment Variables 
  383.    o  localeconv  - Query Locale Conventions 
  384.    o  _putenv - Modify Environment Variables 
  385.    o  locale.h 
  386.  
  387.  Example of setlocale 
  388.  
  389.   #include <stdio.h>
  390.   #include <locale.h>
  391.  
  392.   char *string;
  393.  
  394.   int main(void) {
  395.  
  396.      string = setlocale(LC_ALL, "");     /* adopt parent session locale */
  397.  
  398.      if (string != NULL) printf(" %s \n",string);   /* show what it is */
  399.   }
  400.  
  401.  This example sets the locale of the program to be what the session is and 
  402.  prints the string that is associated with the locale. If LANG were set to 
  403.  En_US, then the program would display: 
  404.  
  405.  
  406.       En_US En_US En_US En_US En_US En_US
  407.  
  408.  
  409. ΓòÉΓòÉΓòÉ 3. Message Catalog Functions ΓòÉΓòÉΓòÉ
  410.  
  411.  
  412. ΓòÉΓòÉΓòÉ 3.1. CATOPEN -- Opens a specified message catalog ΓòÉΓòÉΓòÉ
  413.  
  414.  
  415. Syntax 
  416.  
  417. #include <nl_types.h>
  418.  
  419. nl_catd catopen(const char *name, int oflag);
  420.  
  421. Description 
  422.  
  423. The catopen subroutine opens a specified message catalog and returns a catalog 
  424. descriptor used to retrieve messages from the catalog. The contents of the 
  425. catalog descriptor are complete when the catgets subroutine accesses the 
  426. message catalog.  The nl_catd data type is used for catalog descriptors. This 
  427. data type is defined in the nl_types.h file. 
  428.  
  429. If the catalog file name referred to by the CatalogName parameter contains a 
  430. drive letter on a leading \, it is assumed to be an absoute pathname.  If the 
  431. catalog file  name  is  not  an  absolute path name,  the user environment 
  432. determines which directory  paths to search.  The NLSPATH environment variable 
  433. defines the directory search path.  When this variable is used, the setlocale 
  434. subroutine must be called before the catopen subroutine. 
  435.  
  436. You can use two special variables, %N and %L, in the NLSPATH environment 
  437. variable.  The %N variable is replaced by the catalog name referred to by the 
  438. call that opens the message catalog.  The %L variable is replaced by the value 
  439. of the LC_MESSAGES category. 
  440.  
  441. The value of the LC_MESSAGES category can be set by specifying values for the 
  442. LANG, LC_ALL, or LC_MESSAGES environment variable.  The value of the 
  443. LC_MESSAGES category indicates which locale specific directory to search for 
  444. message catalogs.  For example, if the catopen subroutine specifies a catalog 
  445. with the name mycmd, and the environment variables are set as follows: 
  446.  
  447.     NLSPATH=..\%N:.\%N:\system\nls\%L\%N:\system\nls\%N
  448.     LANG=Fr_FR
  449.  
  450. then the application searches for the catalog in the following order: 
  451.  
  452.    o  ..\mycmd 
  453.  
  454.    o  .\mycmd 
  455.  
  456.    o  \system/\ls\Fr_FR\mycmd 
  457.  
  458.    o  \system\nls\mycmd 
  459.  If you omit the %N variable in a directory specification within the NLSPATH 
  460.  environment variable, the application assumes that the path defines a 
  461.  directory and searches for the catalog in that directory before searching the 
  462.  next specified path. 
  463.  
  464.  If the NLSPATH environment variable is not defined, the default path of 
  465.  \usr\lib\nls\msg\%L\%N;\usr\lib\nls\msg\prime\ %N is used.  If the LC_MESSAGES 
  466.  category is set to the C locale(LC_MESSAGES=C), then the NLSPATH variable 
  467.  mechanism is disabled.  Subsequent calls to the catgets subroutine generate 
  468.  pointers to the program-supplied default text. 
  469.  Parameters 
  470.  
  471.  CatalogNameSpecifies the catalog file to open. 
  472.  
  473.  Parameter Included for compatibility with X/Open, but not used by this 
  474.            operating system.  Use a value of 0. 
  475.  
  476.  Return Values 
  477.  
  478.  The catopen subroutine returns a catalog descriptor.  If the LC_MESSAGES 
  479.  category is set to the default value C, the catopen subroutine returns a value 
  480.  of -1. 
  481.  
  482.  If the LC_MESSAGES category is not set to C but the catopen subroutine returns 
  483.  a value of -1, an error has occurred during creation of the nl_catd structure. 
  484.  Error Codes 
  485.  
  486.  EACCES    Read permission is denied for the message catalog or search 
  487.            permission is denied for the component of the path prefix of the 
  488.            message catalog. 
  489.  
  490.  EMFILE    There are OPEN_MAX file descriptors currently open. 
  491.  
  492.  ENAMETOOLONG The pathname component is longer than NAME_MAX or the length of 
  493.            the pathname of the message catalog exceeds PATH_MAX. 
  494.  
  495.  ENFILE    Too many files open in the system. 
  496.  
  497.  ENOENT    The name argument points to an empty string or the message catalog 
  498.            does not exist. 
  499.  
  500.  ENOMEM    There is not enough storage space available. 
  501.  
  502.  ENOTDIR   File is not found in the directory. 
  503.  
  504.  Related Information 
  505.  
  506.    o  catclose - close a message catalog file. 
  507.    o  catgets - read a message. 
  508.    o  setlocale - envoke a locale. 
  509.  
  510.  Example 
  511.  
  512.   #include<nl_types.h>
  513.  
  514.   void load_cat(char *tcat) {
  515.       nl_catd catd;         /*---- catalog descriptor ----*/
  516.       char cat[PATH_MAX];
  517.  
  518.       if (strchr(tcat,'\')) {
  519.         strcpy(cat,tcat);
  520.         }
  521.  
  522.       else {
  523.         sprintf(cat,".\%s",tcat);
  524.         }
  525.  
  526.       if (access(cat,R_OK)) return;     /* check to see if cat file exists */
  527.  
  528.       if ((catd = catopen( cat , 0)) == CATD_ERR) {
  529.         printf("Unable to load specified catalog. \n");
  530.         exit (1);
  531.         }
  532.  
  533.       if(catclose(catd)==-1)
  534.         perror("Error when trying to close catalog file");
  535.  
  536.       }
  537.  
  538.  
  539. ΓòÉΓòÉΓòÉ 3.2. CATGETS -- Retrieves a message from a catalog ΓòÉΓòÉΓòÉ
  540.  
  541.  
  542. Syntax 
  543.  
  544. #include <wchar.h>
  545.  
  546. char *catgets(nl_catd catd, int setid, int msgid, const char *s);
  547.  
  548. Description 
  549.  
  550. The catgets subroutine retrieves a message from a catalog and constructs a 
  551. message based on the setid + mesid + message. If the catgets subroutine finds 
  552. the specified message, it loads it into an internal character string  buffer, 
  553. ends the  message  string with a null character, and returns a pointer to the 
  554. buffer. 
  555.  
  556. The returned pointer is used to reference the buffer and display the message. 
  557. However, the buffer can not be referenced after the catalog is closed. 
  558. Parameters 
  559.  
  560.  CatalogDescriptorSpecifies a catalog description that is returned by the 
  561.            catopen subroutine. 
  562.  
  563.  SetNumber Specifies the set ID. 
  564.  
  565.  MessageNumberSpecifies the message ID.  The SetNumber and MessageNumber 
  566.            parameters specify a particular message in the catalog to retrieve. 
  567.  
  568.  String    Specifies the default character-string buffer. 
  569.  
  570.  Return Value 
  571.  
  572.  If the catgets subroutine is unsuccessful for any reason, it returns the 
  573.  user-supplied  default  message string specified by the String parameter. 
  574.  Related Information 
  575.  
  576.    o  catclose - close a message catalog. 
  577.    o  catopen - open a message catalog. 
  578.    o  nl_types.h - header file for message functions. 
  579.  
  580.  Example 
  581.  
  582.   #include<nl_types.h>
  583.  
  584.   char *catg(char *tcat, int setno, int msgno, char *def) {
  585.       nl_catd catd;         /*---- catalog descriptor ----*/
  586.       char cat[PATH_MAX];
  587.  
  588.       if (strchr(tcat,'\')) {
  589.         strcpy(cat,tcat);
  590.         }
  591.  
  592.       else {
  593.         sprintf(cat,".\%s",tcat);
  594.         }
  595.  
  596.       if (access(cat,R_OK)) return;     /* if cat file exists --> return */
  597.  
  598.       if ((catd = catopen( cat , 0)) == CATD_ERR) {
  599.         printf("Unable to load specified catalog. \n");
  600.         exit (1);
  601.         }
  602.  
  603.       catgets(catd, setno, msgno, def);
  604.  
  605.       printf("ERROR MESSAGE : %s\n",def);
  606.  
  607.       if (catclose(catd)==-1)
  608.         perror("Error when trying to close catalog file");
  609.  
  610.       }
  611.  
  612.  This example opens a message file with the name contained in tcat and prints 
  613.  out the message associated with set number in setno and the message number in 
  614.  msgno. 
  615.  
  616.  
  617. ΓòÉΓòÉΓòÉ 3.3. CATCLOSE -- closes a specified message catalog ΓòÉΓòÉΓòÉ
  618.  
  619.  
  620. Syntax 
  621.  
  622. #include <nl_types.h>
  623.  
  624. int catclose(nl_catd catd);
  625.  
  626. Description 
  627.  
  628. The function catclose is used to close the catalog message file specified by 
  629. the parameter "catd", that was previously opened by catopen.  Successful return 
  630. is 0.  Unsuccessful return is -1 and ERRNO is set. 
  631. Related Information 
  632.  
  633.    o  catgets - read a message from the message catalog. 
  634.    o  catopen - open a message catalog. 
  635.    o  nl_types.h. 
  636.  
  637.  Example 
  638.  
  639.   #include<nl_types.h>
  640.  
  641.   void load_cat(char *tcat) {
  642.       nl_catd catd;         /*---- catalog descriptor ----*/
  643.       char cat[PATH_MAX];
  644.  
  645.       if (strchr(tcat,'\')) {
  646.         strcpy(cat,tcat);
  647.       }
  648.       else {
  649.         sprintf(cat,".\%s",tcat);
  650.       }
  651.  
  652.       if (access(cat,R_OK)) return;  /* check to see if cat file exists */
  653.  
  654.       if ((catd = catopen( cat , 0)) == CATD_ERR) {
  655.         printf("Unable to load specified catalog. \n");
  656.         exit (1);
  657.         }
  658.  
  659.       if (catclose(catd)==-1)
  660.         perror("Error when trying to close catalog file");
  661.  
  662.       }
  663.  
  664.  This example opens and closes a catalog message file. 
  665.  
  666.  
  667. ΓòÉΓòÉΓòÉ 4. File I/O Functions ΓòÉΓòÉΓòÉ
  668.  
  669.  
  670. ΓòÉΓòÉΓòÉ 4.1. FGETWC -- Read a single WCHAR character ΓòÉΓòÉΓòÉ
  671.  
  672.  
  673. Syntax 
  674.  
  675. #include <wchar.h>
  676.  
  677. wint_t fgetwc(FILE *stream);
  678.  
  679. Description 
  680.  
  681. The fgetwc function reads a single multi-byte character from the input stream 
  682. at the current position, returns it in wide character format and advances the 
  683. associated file pointer, if any, so that it points to the next wide character. 
  684.  
  685. The fgetwc function returns the character read as an  wint_t.  An WEOF return 
  686. value indicates an error or an end-of-file condition.  Use feof or ferror to 
  687. determine whether the WEOF value indicates an error or the end of the file. 
  688. Related Information 
  689.  
  690.    o  feof  - Test End-of-File Indicator 
  691.    o  ferror  - Test for Read/Write Errors 
  692.    o  fopen  - Open File 
  693.    o  wchar 
  694.  
  695.  Example 
  696.  
  697.   #include <wchar.h>
  698.   #include <stdio.h>
  699.   #define  MAX_LEN  26
  700.  
  701.   int main(void) {
  702.       FILE *stream;
  703.       wchar_t buffer[MAX_LEN + 1];
  704.       size_t i;
  705.       wint_t ch;
  706.  
  707.       stream = fopen("myfile.dat","r");
  708.  
  709.       for (i = 0;((i < MAX_LEN)
  710.         && ((ch =  fgetwc(stream)) != WEOF)
  711.         && (ch != '\n')); i++)
  712.            buffer[i] = ch;
  713.  
  714.       buffer[i] = NULL;
  715.  
  716.       printf("%S",buffer);
  717.  
  718.       if (fclose(stream)) perror("fclose error");
  719.  
  720.     }
  721.   /***************  If myfile.dat contains  ********************
  722.  
  723.            ABCDEFGHIJKLMNOPQRSTUVWXYZ1000000A0.013400
  724.  
  725.   *******************  expected output is:  ********************
  726.  
  727.   ABCDEFGHIJKLMNOPQRSTUVWXYZ
  728.  
  729.  This example gathers a single line of input from a stream. 
  730.  
  731.  
  732. ΓòÉΓòÉΓòÉ 4.2. FGETWS -- Read a string of wide characters ΓòÉΓòÉΓòÉ
  733.  
  734.  
  735. Syntax 
  736.  
  737. #include <wchar.h>
  738.  
  739. wchar_t *fgetws (wchar_t *ws, int n, FILE *stream);
  740.  
  741. Description 
  742.  
  743. The fgetws function reads multibyte characters from the current stream position 
  744. up to and including the first new-line character (\n), up to the end of the 
  745. stream, or until the number of characters read is equal to n-1, whichever comes 
  746. first.  The fgetws  function stores the result in string and adds a null 
  747. character (\0) to the end of the string.  The string includes the new-line 
  748. character, if read.  If n is equal to 1, the string contains a wide character 
  749. new-line only. 
  750.  
  751. The fgetws function returns a pointer to the string buffer if successful.  A 
  752. NULL return value indicates an error or an end-of-file condition.  Use feof or 
  753. ferror to determine whether the NULL value indicates an error or the end of the 
  754. file. In either case, the value of the string is unchanged.  See fgetwc for 
  755. possible returned errors. 
  756. Related Information 
  757.  
  758.    o  feof  - Test End-of-File Indicator. 
  759.    o  ferror  - Test for Read/Write Errors. 
  760.    o  fputws  - Print Strings. 
  761.    o  wchar.h  - include file for the wide character functions. 
  762.  
  763.  Example 
  764.  
  765.   #include <stdio.h>
  766.   #include <wchar.h>
  767.   #define  MAX_LEN  27
  768.  
  769.   int main(void) {
  770.       FILE *stream;
  771.       wchar_t line[MAX_LEN], *result;
  772.  
  773.       stream = fopen("myfile.dat","rb");
  774.  
  775.       if ((result = fgetws(line,MAX_LEN,stream)) != NULL)
  776.         printf("The string is %S\n", result);
  777.  
  778.       if (fclose(stream)) perror("fclose error");
  779.       }
  780.  
  781.   ****************  If myfile.dat contains  ********************
  782.  
  783.            ABCDEFGHIJKLMNOPQRSTUVWXYZ1000000A0.013400
  784.  
  785.   *******************  expected output is:  ********************
  786.  
  787.   The string is ABCDEFGHIJKLMNOPQRSTUVWXYZ
  788.  
  789.  This example gets a line of input from a data stream. The example reads no 
  790.  more than MAX_LEN - 1 characters, or up to a new-line character, from the 
  791.  stream. 
  792.  
  793.  
  794. ΓòÉΓòÉΓòÉ 4.3. FPUTWC -- Write one wide character to stream ΓòÉΓòÉΓòÉ
  795.  
  796.  
  797. Syntax 
  798.  
  799. #include <stdio.h>
  800. #include <wchar.h>  /* needed when running Cset2 */
  801.  
  802. wint_t fputwc(wint_t wc, FILE *stream);
  803.  
  804. Description 
  805.  
  806. The fputwc function converts the wide character wc to an multibyte character 
  807. and then writes the multibyte character to the output stream at the current 
  808. position and advances the file position appropriately. If the stream is opened 
  809. with one of the append modes, the character is appended to the end of the 
  810. stream. 
  811.  
  812. The fputwc function normally returns the character written. A return value of 
  813. WEOF indicates an error. 
  814. Related Information 
  815.  
  816.    o  fgetwc  - Read a Wide Character. 
  817.    o  putwc  - Write a Wide Character. 
  818.    o  wchar.h  -  Header file for wide character prototypes. 
  819.  
  820.  Example 
  821.  
  822.   #include <stdio.h>
  823.   #include <wchar.h>
  824.   #define NUM_ALPHA  80
  825.   int main(void) {
  826.       FILE * stream;
  827.       int i;
  828.       wint_t ch;
  829.  
  830.       wchar_t buffer[NUM_ALPHA];
  831.  
  832.       mbstowcs(buffer,"abcdefghijklmnopqrstuvwxyz",NUM_ALPHA);
  833.  
  834.       if (( stream = fopen("myfile.dat", "w"))!= NULL ) {
  835.         for (i=0; i<(int)wcslen(buffer); ++i)   /* Put buffer into file */
  836.         ch=fputwc(buffer[i], stream);
  837.         fclose( stream );
  838.         }
  839.  
  840.       else perror( "Error opening myfile.dat" );
  841.  
  842.       }
  843.  
  844.  This example writes the contents of buffer to a file called myfile.dat. 
  845.  
  846.  Note:  Because the output occurs as a side effect within the second expression 
  847.  of the for statement, the statement body is null. 
  848.  
  849.  
  850. ΓòÉΓòÉΓòÉ 4.4. FPUTWS -- Write a Wide Character String to Stream ΓòÉΓòÉΓòÉ
  851.  
  852.  
  853. Syntax 
  854.  
  855. #include <stdio.h>
  856. #include <wchar.h>  /* needed when running Cset2 */
  857.  
  858. int fputws(const wchar_t *string, FILE *stream);
  859.  
  860. Description 
  861.  
  862. The fputws function copies string to the output stream at the current position. 
  863. It does not copy the NULL character (\0) at the end of the string. 
  864.  
  865. If an error occurs, the fputws function returns EOF and set errno;  otherwise, 
  866. it returns a non-negative value. 
  867. Related Information 
  868.  
  869.    o  fgetws  - Read a String 
  870.    o  wchar.h  -  Header file for wide character prototypes. 
  871.  
  872.  Example 
  873.  
  874.   #include <stdio.h>
  875.   #include <wchar.h>
  876.   #define NUM_ALPHA  80
  877.   int main(void) {
  878.       FILE * stream;
  879.       int num;
  880.       wint_t ch;
  881.  
  882.       wchar_t buffer[NUM_ALPHA];
  883.  
  884.       mbstowcs(buffer,"abcdefghijklmnopqrstuvwxyz",NUM_ALPHA);
  885.  
  886.       if ((stream=fopen("myfile.dat", "w")) != NULL) {
  887.         num=fputws(buffer, stream);    /* Put buffer into file */
  888.  
  889.         /* Note that fputws() does not copy the NULL character */
  890.  
  891.         printf( "Total number of characters written to file = %i\n", num );
  892.  
  893.         fclose( stream );
  894.         }
  895.  
  896.       else perror( "Error opening myfile.dat" );
  897.       }
  898.  
  899.  This example writes a string to a stream. 
  900.  
  901.  
  902. ΓòÉΓòÉΓòÉ 4.5. GETWC -- Reads data from stream ΓòÉΓòÉΓòÉ
  903.  
  904.  
  905. Syntax 
  906.  
  907. #include <sdtio.h>
  908. #include <wchar.h>  /* required if using Cset2 */
  909.  
  910. wint_t getwc(FILE *stream);
  911.  
  912. Dscription. 
  913.  
  914. The getwc function reads a single wide character from the current stream 
  915. position and advances the stream position to the next wide character. 
  916.  
  917. The getwc function returns the character read.  A return value of WEOF 
  918. indicates an error or end-of-file condition.  Errno will be set if any error 
  919. occurs. 
  920. Related Information 
  921.  
  922.    o  fgetwc  - Read a Wide Character. 
  923.    o  putwc - Write a Wide Character. 
  924.    o  wchar.h  - Header file for Wide Character Prototypes. 
  925.  
  926.  Example 
  927.  
  928.   #include <stdio.h>
  929.   #include <wchar.h>
  930.  
  931.   #define LINE 80
  932.  
  933.   int main(void) {
  934.       wchar_t buffer[LINE+1];
  935.       int i;
  936.       wint_t ch;
  937.  
  938.       printf( "Please enter string\n" );
  939.  
  940.       /*
  941.       Keep reading until either:
  942.       1. the length of LINE is exceeded  or
  943.       2. the input character is EOF  or
  944.       3. the input character is a new-line character
  945.       */
  946.  
  947.       for (i=0; (i < LINE) && ((ch=getwc()) != EOF)
  948.         && (ch!='\n'); ++i)
  949.           buffer[i] = ch;
  950.  
  951.       buffer[i]=NULL;                 /* NULL terminator for string */
  952.  
  953.       printf( "The string is %ls\n", buffer );
  954.       }
  955.  
  956.   /****************  Output should be similar to:  ******************
  957.  
  958.   Please enter string
  959.   hello world
  960.   The string is hello world
  961.  
  962.   *******************************************************************/
  963.  
  964.  This example gets a line of input from the stdin stream. You can also use 
  965.  getwc(stdin) instead of getchar() in the for statement to get a line of input 
  966.  from stdin. 
  967.  
  968.  
  969. ΓòÉΓòÉΓòÉ 4.6. GETWCHAR -- Gets a wide character from an input stream ΓòÉΓòÉΓòÉ
  970.  
  971.  
  972. Syntax 
  973.  
  974. #include <wchar.h>
  975.  
  976. wint_t getwchar(void);
  977.  
  978. Description 
  979.  
  980. The getwchar subroutine is equivalent to the getwc subroutine with stdin as the 
  981. input stream. 
  982.  
  983. The getwchar subroutine returns the next wide character from the input stream 
  984. pointed to by stdin.  Errno is set to the following if an error occurs: ENOMEM 
  985. Storage space is insufficient. ENXIO  The process sent a request to a 
  986. nonexistent device, or the device cannot handle the request. EILSEQ  The wc 
  987. wide character code does not correspond to a valid character. 
  988. Related Information 
  989.  
  990.    o  getwc  - Get a wide character. 
  991.    o  fgetwc  -  Get a wide character from the input stream. 
  992.    o  wchar.h  - Header file for wide character prototypes. 
  993.  
  994.  Example 
  995.  
  996.   #include <stdio.h>
  997.   #include <wchar.h>
  998.   int main (void) {
  999.       wint_t ch;
  1000.  
  1001.       printf("\nType in some letters.");
  1002.       printf("\n");
  1003.  
  1004.       for(;;) {
  1005.         ch = getwchar();
  1006.         putwchar(ch);
  1007.         }
  1008.  
  1009.       return 1;
  1010.       }
  1011.  
  1012.  This example gets wide characters from the keyboard and echoes them back to 
  1013.  the screen. 
  1014.  
  1015.  
  1016. ΓòÉΓòÉΓòÉ 4.7. PUTWC -- Writes a wide character to the output stream ΓòÉΓòÉΓòÉ
  1017.  
  1018.  
  1019. Syntax 
  1020.  
  1021. #include <stdio.h>
  1022. #include <wchar.h>
  1023.  
  1024. wint_t putwc(wint_t wc, FILE *stream);
  1025.  
  1026. Description 
  1027.  
  1028. The putwc function converts wc to wide char and then writes wc to the output 
  1029. stream at the current position. 
  1030.  
  1031. The putwc function returns the character written. A return value of WEOF 
  1032. indicates an error. 
  1033. Related Information 
  1034.  
  1035.    o  fputwc  - Write a Wide Character 
  1036.    o  getwc - getchar - Read a Wide Character 
  1037.    o  putws  - Write a Wide String 
  1038.    o  wchar.h 
  1039.  
  1040.  Example 
  1041.  
  1042.   #include <stdio.h>
  1043.   #include <wchar.h>
  1044.   #include <lc_core.h>
  1045.  
  1046.   int main(void) {
  1047.       FILE *stream = stdout;
  1048.       int i;
  1049.       wchar_t ws[200];
  1050.       char *s = "hello world";
  1051.  
  1052.       mbstowcs(ws, s, strlen(s));
  1053.  
  1054.       for ( i = 0; i < wcslen(ws); i++ )
  1055.         if (putwc(ws[i], stream) == WEOF) {
  1056.           perror("Stream I/O Failure");
  1057.           break;
  1058.           }
  1059.  
  1060.       }
  1061.  
  1062.   /********************  Expected output:  **************************
  1063.  
  1064.   Hello world
  1065.  
  1066.   *******************************************************************/
  1067.  
  1068.  This example writes the contents of a buffer to a data stream.  In this 
  1069.  example, the body of the for statement is null because the example carries out 
  1070.  the writing operation in the test expression. 
  1071.  
  1072.  
  1073. ΓòÉΓòÉΓòÉ 4.8. PUTWCHAR -- Writes a wide character to a stream ΓòÉΓòÉΓòÉ
  1074.  
  1075.  
  1076. Syntax 
  1077.  
  1078. #include <wchar.h>
  1079.  
  1080. wint_t putwchar(wint_t wc);
  1081.  
  1082. Description 
  1083.  
  1084. The putwchar subroutine works like the putwc subroutine, except that putwchar 
  1085. writes the specified wide character to the standard output.  Output streams, 
  1086. with the exception of stderr, are buffered by default if they refer to files, 
  1087. or line-buffered if they refer  to terminals. 
  1088.  
  1089. Upon successful completion, the putwc, putwchar, and fputwc subroutines return 
  1090. the wide character that is  written.  OtherwiseWEOF is returned, the error 
  1091. indicator for the stream is set, and the errno global variable is set to: 
  1092. EAGAIN  The O_NONBLOCK flag is set for the file descriptor under lying the 
  1093. Stream parameter, delaying the process during the write operation.  EBADF  The 
  1094. file descriptor underlying the Stream parameter is not valid and cannot be 
  1095. updated during the write operation.  EFBIG  The process attempted to write to a 
  1096. file that already equals or exceeds the file-size limit for the process.  EINTR 
  1097. The process has received a signal that terminates the read operation.  EIO 
  1098. The process is in a background process group attempting to perform  a  write 
  1099. operation  to  its  controlling terminal.  The TOSTOP flag is set, the process 
  1100. is not ignoring or blocking the SIGTTOU flag, and the process group of the 
  1101. process is orphaned.  ENOSPC  No free space remains on the device containing 
  1102. the file.  ENOMEM  Insufficient storage space available.  ENXIO  A request was 
  1103. made of a non-existant device, or the request was outside the capabilities of 
  1104. the device.  EILSEQ  The wide-character code does not correspond to a valid 
  1105. character. 
  1106. Related Information 
  1107.  
  1108.    o  fputwc  - Put a wide character out to a stream. 
  1109.    o  putwc  - Put a wide character to std out. 
  1110.    o  wchar.h  - Header file for wide character prototypes. 
  1111.  
  1112.  Example 
  1113.  
  1114.   #include <stdio.h>
  1115.   #include <wchar.h>
  1116.   int main (void) {
  1117.       wint_t ch;
  1118.  
  1119.       cprintf("\nType in some letters.");
  1120.       printf("\n");
  1121.       for(;;) {
  1122.         ch = getwchar();
  1123.         putwchar(ch);
  1124.         }
  1125.  
  1126.       return 1;
  1127.       }
  1128.  
  1129.  This example gets wide characters from the keyboard and prints them out using 
  1130.  putwchar. 
  1131.  
  1132.  
  1133. ΓòÉΓòÉΓòÉ 4.9. UNGETWC -- Push wide-character onto input stream ΓòÉΓòÉΓòÉ
  1134.  
  1135.  
  1136. Syntax 
  1137.  
  1138. #include <stdio.h>
  1139. #include <wchar.h>
  1140.  
  1141. wint_t ungetwc(wint_t wc, FILE *stream);
  1142.  
  1143. Description 
  1144.  
  1145. The ungetwc function pushes the wide character pointed to by wc back onto the 
  1146. given input stream.  However, only one sequential ungetwc is guaranteed to be 
  1147. pushed back onto the input stream if you call ungetwc consecutively. The stream 
  1148. must be open for reading.  A subsequent read operation on the stream starts 
  1149. with wc.  You cannot push WEOF back on the stream using ungetwc. 
  1150.  
  1151. Characters placed on the stream by ungetwc will be erased if a fseek, fsetpos, 
  1152. rewind, or fflush function is called before the character is read from the 
  1153. stream. 
  1154. Related Information 
  1155.  
  1156.    o  getwc - Read a Wide Character 
  1157.    o  putwc - Write a Wide Character 
  1158.    o  wchar.h 
  1159.  
  1160.  Example 
  1161.  
  1162.   #include <stdio.h>
  1163.   #include <ctype.h>
  1164.   #include <wchar.h>
  1165.  
  1166.   int main(void) {
  1167.       FILE *stream;
  1168.       int ch;
  1169.       unsigned int result = 0;
  1170.  
  1171.       while ((ch = getc(stream)) != EOF && isdigit(ch))
  1172.         result = result * 10 + ch - '0';
  1173.  
  1174.       if (ch != EOF) ungetwc(ch,stream);
  1175.       }
  1176.  
  1177.  In this example, the while statement reads decimal digits from an input data 
  1178.  stream by using arithmetic statements to compose the numeric values of the 
  1179.  numbers as it reads them.  When a nondigit character appears before the endof 
  1180.  the file, ungetwc replaces it in the input stream so that later input 
  1181.  functions can process it. 
  1182.  
  1183.  
  1184. ΓòÉΓòÉΓòÉ 5. ICONV Functions ΓòÉΓòÉΓòÉ
  1185.  
  1186.  
  1187. ΓòÉΓòÉΓòÉ 5.1. ICONV_OPEN -- Access to conversion descriptor ΓòÉΓòÉΓòÉ
  1188.  
  1189.  
  1190. Syntax 
  1191.  
  1192. #include <iconv.h>
  1193.  
  1194. iconv_t iconv_open(const char *target, const char *source);
  1195.  
  1196. Description 
  1197.  
  1198. The iconv_open function is used to obtain an iconv_t descriptor that describes 
  1199. the conversion from the source code set to the target code set. For state 
  1200. dependant conversions, icon_open starts in the initial unshifted state. 
  1201. Related Information 
  1202.  
  1203.    o  iconv  - Converts string of char from one character code set to another. 
  1204.    o  iconv_close  - Deallocates all resources allocated by iconv_open. 
  1205.    o  iconv.h  - Header file for iconv prototypes. 
  1206.  
  1207.  Example 
  1208.  
  1209.   See iconv for example.
  1210.  
  1211.  
  1212. ΓòÉΓòÉΓòÉ 5.2. ICONV -- Converts string of char from one character code set to another ΓòÉΓòÉΓòÉ
  1213.  
  1214.  
  1215. Syntax 
  1216.  
  1217. #include <iconv.h>
  1218.  
  1219. size_t iconv(iconv_t CD, const char **InBuf, size_t *InBytesLeft,
  1220.              char **OutBuf, size_t *OutBytesLeft);
  1221.  
  1222.  CD        Specifies the conversion descriptor that points to the correct code 
  1223.            set converter. 
  1224.  
  1225.  InBuf     Points to a buffer that contains the number of bytes in InBytesLeft 
  1226.            to be converted. 
  1227.  
  1228.  InBytesLeft Points to an integer that contains the number of bytes in InBuf. 
  1229.  
  1230.  OutBuf    Points to a buffer that contains the number of bytes in OutBytesLeft 
  1231.            that have been converted. 
  1232.  
  1233.  OutBytesLeft Points to an integer that contains the number of bytes in OutBuf. 
  1234.  
  1235.  Description 
  1236.  
  1237.  The iconv subroutine converts the string specified by the InBuf parameter into 
  1238.  a  different  code set and returns the results in the OutBuf parameter.  The 
  1239.  required conversion method is identified by the CD parameter, which must be a 
  1240.  valid conversion descriptor returned  by  a  previous, successful call to the 
  1241.  iconv_open subroutine. 
  1242.  
  1243.  On calling, the InBytesLeft parameter indicates the number of bytes in the 
  1244.  InBuf buffer to be converted, and the OutBytesLeft parameter indicates the 
  1245.  number of available bytes in the OutBuf buffer.  These  values are updated 
  1246.  upon return so they indicate the new state of their associated buffers.  For 
  1247.  state-dependent encodings, calling the iconv subroutine with the InBuf buffer 
  1248.  set to null will reset the conversion descriptor in the CD parameter to its 
  1249.  initial state. Subsequent calls with the InBuf buffer, specifying other than a 
  1250.  NULL pointer, may cause the internal state of the subroutine to be altered as 
  1251.  necessary.  Upon successful conversion of all the characters in the InBuf 
  1252.  buffer and after placing the converted characters in the OutBuf buffer, the 
  1253.  iconv subroutine returns 0, updates the InBytesLeft and OutBytesLeft 
  1254.  parameters, and increments the InBuf and OutBuf pointers.  If the iconv 
  1255.  subroutine is unsuccessful, it updates the variables to reflect the extent of 
  1256.  the  conversion  before  it stopped, and sets errno to one of the following 
  1257.  values: 
  1258.  
  1259.  EILSEQ    The conversion has been stopped due to an input byte that does not 
  1260.            belong to the input codeset. 
  1261.  
  1262.  E2BIG     The conversion has been stopped due to lack of space in the output 
  1263.            buffer. 
  1264.  
  1265.  EINVAL    The conversion has been stopped due to an incomplete character or 
  1266.            shift sequence at the end of the input buffer. 
  1267.  
  1268.  EBADF     The argument CD is invalid. 
  1269.  
  1270.  Related Information 
  1271.  
  1272.    o  genxlt 
  1273.    o  iconv_open  - allocates all resources needed by iconv. 
  1274.    o  iconv_close  - Deallocates all resources allocated by iconv_open. 
  1275.    o  iconv.h  - Header file for iconv prototypes. 
  1276.  
  1277.  Example 
  1278.  
  1279.   #include <stdlib.h>
  1280.   #include <stdio.h>
  1281.   #include <string.h>
  1282.   #include <wchar.h>
  1283.   #include <iconv.h>
  1284.   #define  MAX_LEN  255
  1285.  
  1286.   int main(void) {
  1287.       char *from = "IBM-037",
  1288.       char *to   = "IBM-850";
  1289.  
  1290.       char buf2[256];
  1291.       long i;
  1292.  
  1293.       iconv_t cd;
  1294.  
  1295.       char *inptr;
  1296.       char *outptr;
  1297.  
  1298.       size_t inleft;
  1299.       size_t outleft;
  1300.       size_t ret;
  1301.  
  1302.       char line[MAX_LEN] = "THIS IS THE LINE TO CONVERT",
  1303.       char result[MAX_LEN];
  1304.  
  1305.       buf2[0] = NULL;
  1306.       inptr = line;
  1307.       inleft = strlen(inptr);
  1308.       outleft = sizeof(buf2);
  1309.       outptr = buf2;
  1310.  
  1311.       printf("Converting from %s to %s.\n",from,to);
  1312.       cd = iconv_open(from,to);
  1313.  
  1314.       if ((int) cd <= 0) {
  1315.         printf("ERROR OPENING ICONV TABLES");
  1316.         return 1;
  1317.         }
  1318.  
  1319.       ret = iconv(cd, &inptr, &inleft, &outptr, &outleft);
  1320.       *outptr = NULL;
  1321.  
  1322.       printf("original string: %s\n",line);
  1323.       printf("modified string: %s\n",buf2);
  1324.  
  1325.       iconv_close(cd);
  1326.       return(1);
  1327.       }
  1328.  
  1329.  This program is used to convert all the characters from one character table 
  1330.  IBM-437 to another IBM-850.  The characters are contained in the variable 
  1331.  "line". 
  1332.  
  1333.  
  1334. ΓòÉΓòÉΓòÉ 5.3. ICONV_CLOSE -- Deallocates all resources allocated by iconv_open ΓòÉΓòÉΓòÉ
  1335.  
  1336.  
  1337. Syntax 
  1338.  
  1339. #include <iconv.h>
  1340.  
  1341. int iconv_close(iconv_t *cd);
  1342.  
  1343. Description 
  1344.  
  1345. The function iconv_close is used to deallocate all resources that have been 
  1346. allocated by the iconv_open function including the conversion descriptor that 
  1347. is specified by the pointer "*cd". 
  1348. Related Information 
  1349.  
  1350.    o  iconv  - Converts string of char from one character code set to another. 
  1351.    o  iconv_open  - allocates all resources needed by iconv. 
  1352.    o  iconv.h  - Header file for iconv prototypes. 
  1353.  
  1354.  Example 
  1355.  
  1356.   See iconv for example.
  1357.  
  1358.  
  1359. ΓòÉΓòÉΓòÉ 6. IS* Functions ΓòÉΓòÉΓòÉ
  1360.  
  1361.  
  1362. ΓòÉΓòÉΓòÉ 6.1. IS* Functions -- Character identification functions ΓòÉΓòÉΓòÉ
  1363.  
  1364.  
  1365. Syntax 
  1366.  
  1367. #include <ctype.h>
  1368.  
  1369. int isalnum(int c); /* Tests for: upper or lowercase letters, or decimal digit */
  1370. int isalpha(int c); /* Tests for: alphabetic character */
  1371. int iscntrl(int c); /* Tests for: any control character */
  1372. int isdigit(int c); /* Tests for: decimal digit */
  1373. int isgraph(int c); /* Tests for: printable character excluding space */
  1374. int islower(int c); /* Tests for: lowercase */
  1375. int isprint(int c); /* Tests for: printable character including space */
  1376. int ispunct(int c); /* Tests for: any nonalphanumeric printable character */
  1377.                                    /* excluding space */
  1378. int isspace(int c); /* Tests for: whitespace character */
  1379. int isupper(int c); /* Tests for: uppercase */
  1380. int isxdigit(int c); /* Tests for: hexadecimal digit */
  1381.  
  1382.  
  1383. Description 
  1384.  
  1385. The <ctype.h> functions listed test a given integer value. They return a 
  1386. nonzero value if the integer satisfies the test condition, or a zero value if 
  1387. it does not. EOF is a valid input value. 
  1388. Related Information 
  1389.  
  1390.    o  tolower - toupper  - Convert Character Case 
  1391.    o  ctype.h 
  1392.  
  1393.  Example 
  1394.  
  1395.   #include <stdio.h>
  1396.   #include <ctype.h>
  1397.  
  1398.   #define UPPER_LIMIT   0xFF
  1399.  
  1400.   int main(void) {
  1401.       int ch;
  1402.  
  1403.       for ( ch = 0; ch <= UPPER_LIMIT; ++ch ) {
  1404.         printf("\n%3d ", ch);
  1405.         printf("%#04x ", ch);
  1406.         printf("%3s ", isalnum(ch)  ? "AN" : " ");
  1407.         printf("%2s ", isalpha(ch)  ? "A"  : " ");
  1408.         printf("%2s",  iscntrl(ch)  ? "C"  : " ");
  1409.         printf("%2s",  isdigit(ch)  ? "D"  : " ");
  1410.         printf("%2s",  isgraph(ch)  ? "G"  : " ");
  1411.         printf("%2s",  islower(ch)  ? "L"  : " ");
  1412.         printf(" %c",  isprint(ch)  ? ch   : ' ');
  1413.         printf("%3s",  ispunct(ch)  ? "PU" : " ");
  1414.         printf("%2s",  isspace(ch)  ? "S"  : " ");
  1415.         printf("%3s",  isprint(ch)  ? "PR" : " ");
  1416.         printf("%2s",  isupper(ch)  ? "U"  : " ");
  1417.         printf("%2s",  isxdigit(ch) ? "X"  : " ");
  1418.         }
  1419.  
  1420.       }
  1421.  
  1422.  This example analyzes all characters between code 0x0 and code UPPER_LIMIT, 
  1423.  printing A for alphabetic characters, AN for alphanumerics, U for uppercase, L 
  1424.  for lowercase, D for digits, X for hexadecimal digits, S for spaces, PU for 
  1425.  punctuation, PR for printable characters, G for graphics characters, and C for 
  1426.  control characters. This example prints the code if printable. 
  1427.  
  1428.  The output of this example is a 256-line table showing the characters from 0 
  1429.  to 255 that possess the attributes tested. 
  1430.  
  1431.  
  1432. ΓòÉΓòÉΓòÉ 6.2. ISW* -- Character identification functions ΓòÉΓòÉΓòÉ
  1433.  
  1434.  
  1435. Syntax 
  1436.  
  1437. #include <wchar.h>
  1438.  
  1439. int iswalnum(wint_t wc); /* Tests for: upper/lowercase letters, and digits */
  1440. int iswalpha(wint_t wc); /* Tests for: alphabetic character */
  1441. int iswcntrl(wint_t wc); /* Tests for: any control character */
  1442. int iswdigit(wint_t wc); /* Tests for: decimal digit */
  1443. int iswgraph(wint_t wc); /* Tests for: printable character excluding space */
  1444. int iswlower(wint_t wc); /* Tests for: lowercase */
  1445. int iswprint(wint_t wc); /* Tests for: printable character including space */
  1446. int iswpunct(wint_t wc); /* Tests for: any nonalphanumeric printable character */
  1447.                                    /* excluding space */
  1448. int iswspace(wint_t wc); /* Tests for: whitespace character */
  1449. int iswupper(wint_t wc); /* Tests for: uppercase */
  1450. int iswxdigit(wint_t wc); /* Tests for: hexadecimal digit */
  1451.  
  1452. Description 
  1453.  
  1454. The <wchar.h> functions listed test a given wide character value. They return a 
  1455. nonzero value if the wide character satisfies the test condition, or a zero 
  1456. value if it does not. 
  1457.  
  1458. wc must be representable as an wide character.  Note:  WEOF is a valid input 
  1459. value. 
  1460. Related Information 
  1461.  
  1462.    o  is* functions 
  1463.    o  wchar.h 
  1464.  
  1465.  Example 
  1466.  
  1467.   #include <stdio.h>
  1468.   #include <wchar.h>
  1469.  
  1470.   #define UPPER_LIMIT   0xFF
  1471.  
  1472.   int main(void) {
  1473.       wint_t ch;
  1474.  
  1475.       for ( ch = 0; ch <= UPPER_LIMIT; ++ch ) {
  1476.         printf("\n%3d ", ch);
  1477.         printf("%#04x ", ch);
  1478.         printf("%3s ", iswalnum(ch)  ? "AN" : " ");
  1479.         printf("%2s ", iswalpha(ch)  ? "A"  : " ");
  1480.         printf("%2s",  iswcntrl(ch)  ? "C"  : " ");
  1481.         printf("%2s",  iswdigit(ch)  ? "D"  : " ");
  1482.         printf("%2s",  iswgraph(ch)  ? "G"  : " ");
  1483.         printf("%2s",  iswlower(ch)  ? "L"  : " ");
  1484.         printf(" %c",  iswprint(ch)  ? ch   : ' ');
  1485.         printf("%3s",  iswpunct(ch)  ? "PU" : " ");
  1486.         printf("%2s",  iswspace(ch)  ? "S"  : " ");
  1487.         printf("%3s",  iswprint(ch)  ? "PR" : " ");
  1488.         printf("%2s",  iswupper(ch)  ? "U"  : " ");
  1489.         printf("%2s",  iswxdigit(ch) ? "X"  : " ");
  1490.         }
  1491.  
  1492.       }
  1493.  
  1494.  This example analyzes all characters between code 0x0 and code UPPER_LIMIT, 
  1495.  printing A for alphabetic characters, AN for alphanumerics, U for uppercase, L 
  1496.  for lowercase, D for digits, X for hexadecimal digits, S for spaces, PU for 
  1497.  punctuation, PR for printable characters, G for graphics characters, and C for 
  1498.  control characters. This example prints the code if printable. 
  1499.  
  1500.  The output of this example is a 256-line table showing the characters from 0 
  1501.  to 255 that possess the attributes tested. 
  1502.  
  1503.  
  1504. ΓòÉΓòÉΓòÉ 6.3. ISWCTYPE -- Class test for characters ΓòÉΓòÉΓòÉ
  1505.  
  1506.  
  1507. Syntax 
  1508.  
  1509. #include <wchar.h>
  1510.  
  1511. int iswctype(wint_t wc, wctype_t mask);
  1512.  
  1513. Description 
  1514.  
  1515. The iswctype functions uses the character class to determine if a wide 
  1516. character is in a specific class.  The character classes are defined in each 
  1517. locale by the following key strings: 
  1518.  
  1519.  "alnum"    -  for the alpha numeric class. 
  1520.  
  1521.  "alpha"    -  for the alphabetic only class. 
  1522.  
  1523.  "cntrl"    -  for the control class. 
  1524.  
  1525.  "digit"    -  for the digit class. 
  1526.  
  1527.  "graph"    -  for the graphics character class. 
  1528.  
  1529.  "lower"    -  for the lower case character class. 
  1530.  
  1531.  "print"    -  for the printable character class. 
  1532.  
  1533.  "punct"    -  for the punctuation class. 
  1534.  
  1535.  "space"    -  for the space character class. 
  1536.  
  1537.  "upper"    -  for the upper case character class. 
  1538.  
  1539.  "xdigit"   -  for the digit or alpha character class. 
  1540.  
  1541.  "blank"    -  for the hexadecimal alpha numeric class. 
  1542.  
  1543.  Related Information 
  1544.  
  1545.    o  wctype 
  1546.    o  wchar.h 
  1547.    o  isw* functions 
  1548.  
  1549.  Example 
  1550.  
  1551.   #include <stdio.h>
  1552.   #include <wchar.h>
  1553.  
  1554.   #define UPPER_LIMIT   0xFF
  1555.  
  1556.   int main(void) {
  1557.       wint_t ch;
  1558.  
  1559.       for ( ch = 0; ch <= UPPER_LIMIT; ++ch ) {
  1560.         printf("\n%3d ", ch);
  1561.         printf("%#04x ", ch);
  1562.         printf("%3s ", iswctype(ch,wctype("alnum"))  ? "AN" : " ");
  1563.         printf("%2s ", iswctype(ch,wctype("alpha"))  ? "A"  : " ");
  1564.         printf("%2s", iswctype(ch,wctype("cntrl"))  ? "C"  : " ");
  1565.         printf("%2s", iswctype(ch,wctype("digit"))  ? "D"  : " ");
  1566.         printf("%2s", iswctype(ch,wctype("graph"))  ? "G"  : " ");
  1567.         printf("%2s", iswctype(ch,wctype("lower"))  ? "L"  : " ");
  1568.         printf(" %c", iswctype(ch,wctype("blank"))  ? "B"  : " ");
  1569.         printf("%3s", iswctype(ch,wctype("punct"))  ? "PU" : " ");
  1570.         printf("%2s", iswctype(ch,wctype("space"))  ? "S"  : " ");
  1571.         printf("%3s", iswctype(ch,wctype("print"))  ? "PR" : " ");
  1572.         printf("%2s", iswctype(ch,wctype("upper"))  ? "U"  : " ");
  1573.         printf("%2s", iswctype(ch,wctype("xdigit")) ? "X"  : " ");
  1574.         }
  1575.  
  1576.       }
  1577.  
  1578.  This example analyzes all characters between code 0x0 and code UPPER_LIMIT, 
  1579.  printing A for alphabetic characters, AN for alphanumerics, U for uppercase, L 
  1580.  for lowercase, D for digits, X for hexadecimal digits, S for spaces, PU for 
  1581.  punctuation, PR for printable characters, G for graphics characters, and C for 
  1582.  control characters. This example prints the code if printable. 
  1583.  
  1584.  The output of this example is a 256-line table showing the characters from 0 
  1585.  to 255 that possess the attributes tested. 
  1586.  
  1587.  
  1588. ΓòÉΓòÉΓòÉ 6.4. TOLOWER / TOUPPER -- Convert character case ΓòÉΓòÉΓòÉ
  1589.  
  1590.  
  1591. Syntax 
  1592.  
  1593. #include <ctype.h>
  1594.  
  1595. int tolower(int c);   /* Convert c to lowercase if appropriate */
  1596.  
  1597. int toupper(int c);   /* Convert c to uppercase if appropriate */
  1598.  
  1599. Description 
  1600.  
  1601. The tolower function returns a lowercase c if c represents an uppercase letter; 
  1602. otherwise, c is returned.  c is unchanged. 
  1603.  
  1604. The toupper function returns an uppercase c if c represents a lowercase letter; 
  1605. otherwise, c is returned. c is unchanged. 
  1606. Related Information 
  1607.  
  1608.    o  isalnum to isxdigit  - Test Integer Value 
  1609.    o  isascii - Test Integer Values 
  1610.    o  toascii - Convert Character 
  1611.    o  tolower - Convert Character 
  1612.    o  toupper - Convert Character 
  1613.    o  wchar.h 
  1614.  
  1615.  Example 
  1616.  
  1617.   #include <stdio.h>
  1618.   #include <ctype.h>
  1619.  
  1620.   int main(void) {
  1621.       int ch;
  1622.  
  1623.       for (ch = 0; ch <= 0x7f; ch++) {
  1624.         printf("\ntoupper=%#04x  -  ", toupper(ch));
  1625.         printf("tolower=%#04x", tolower(ch));
  1626.         }
  1627.  
  1628.       }
  1629.  
  1630.  This example uses the toupper and tolower functions to modify characters 
  1631.  between code 0 and code 7f. 
  1632.  
  1633.  
  1634. ΓòÉΓòÉΓòÉ 7. Locale/MB* Functions ΓòÉΓòÉΓòÉ
  1635.  
  1636.  
  1637. ΓòÉΓòÉΓòÉ 7.1. LOCALECONV -- Defines values for lconv structure based on Locale ΓòÉΓòÉΓòÉ
  1638.  
  1639.  
  1640. Syntax 
  1641.  
  1642. #include <locale.h>
  1643. #include <wchar.h>
  1644.  
  1645. struct lconv *localeconv(void);
  1646.  
  1647. Description 
  1648.  
  1649. The localeconv function sets the components of a structure having type struct 
  1650. lconv to values appropriate for the current locale.  The structure may be 
  1651. overwritten by another call to localeconv or by calling setlocale and passing 
  1652. LC_ALL, LC_MONETARY, or LC_NUMERIC. 
  1653.  
  1654. The structure contains the following elements (defaults shown are for the C 
  1655. locale): 
  1656.  
  1657. ELEMENT                    PURPOSE OF ELEMENT                DEFAULT
  1658.  
  1659.             "char *decimal_point"     Radix character                   "."
  1660.                                       used to format non-monetary
  1661.                                       quantities.
  1662.  
  1663.             "char *thousands_sep"     Character used to separate        ""
  1664.                                       groups of digits to the
  1665.                                       left of the decimal-point
  1666.                                       character in formatted
  1667.                                       nonmonetary quantities.
  1668.  
  1669.             "char *grouping"          String whose elements taken       ""
  1670.                                       as one-byte integer values
  1671.                                       indicate the size of each
  1672.                                       group of digits in formatted
  1673.                                       non-monetary quantities.
  1674.  
  1675.             "char *int_curr_symbol"   International currency            ""
  1676.                                       symbol for the current
  1677.                                       locale.  The first three
  1678.                                       characters contain the
  1679.                                       alphabetic international
  1680.                                       currency symbol.  The
  1681.                                       fourth character (usually
  1682.                                       a space) is the character
  1683.                                       used to separate the
  1684.                                       international currency
  1685.                                       symbol from the monetary
  1686.                                       quantity.
  1687.  
  1688.             "char *currency_symbol"   Local currency symbol of          ""
  1689.                                       the current locale.
  1690.  
  1691.             "char *mon-decimal_point" Radix character                   "."
  1692.                                       used to format monetary
  1693.                                       quantities.
  1694.  
  1695.             "char *mon_thousands_sep" Separator for digits in           ""
  1696.                                       formatted monetary quantities.
  1697.  
  1698.             "char *mon_grouping"      String whose elements taken       ""
  1699.                                       as one-byte integer values
  1700.                                       indicate the size of each
  1701.                                       group of digits in formatted
  1702.                                       monetary quantities.
  1703.  
  1704.             "char *positive_sign"     String indicating a positive
  1705.                                       value formatted monetary
  1706.                                       quantity.
  1707.  
  1708.             "char *negative_sign"     String indicating a negative
  1709.                                       value formatted monetary
  1710.                                       quantity.
  1711.  
  1712.             "char int_frac_digits"    The number of displayed digits    "UCHAR_MAX"
  1713.                                       to the right of the decimal
  1714.                                       place for internationally
  1715.                                       formatted monetary quantities.
  1716.  
  1717.             "char frac_digits"        Number of digits to the           "UCHAR_MAX"
  1718.                                       right of the decimal place
  1719.                                       in monetary quantities.
  1720.  
  1721.             "char p_cs_precedes"      1 if the "currency_symbol" or     "UCHAR_MAX"
  1722.                                       int_curr_symbol precedes the
  1723.                                       value for a non-negative
  1724.                                       formatted monetary quantity;
  1725.                                       0 if it succedes the value.
  1726.  
  1727.             "char p_sep_by_space"     0 if the "currency_symbol" or     "UCHAR_MAX"
  1728.                                       int_curr_symbol is not
  1729.                                       separated by a from the
  1730.                                       value for a non-negative
  1731.                                       formatted space monetary
  1732.                                       quantity;
  1733.                                       1 if a space separates the
  1734.                                       symbol from the value; and
  1735.                                       2 if a space separates the
  1736.                                       symbol and the sign string,
  1737.                                       if adjacent.
  1738.  
  1739.             "char n_cs_precedes"      1 if the "currency_symbol" or     "UCHAR_MAX"
  1740.                                       int_curr_symbol precedes the
  1741.                                       value for a negative
  1742.                                       formatted monetary quantity;
  1743.                                       0 if it succedes the value.
  1744.  
  1745.             "char n_sep_by_space"     0 if the "currency_symbol" or     "UCHAR_MAX"
  1746.                                       int_curr_symbol is not
  1747.                                       separated by a space from the
  1748.                                       value for a negative formatted
  1749.                                       monetary quantity;  1 if a
  1750.                                       space separates the symbol
  1751.                                       from the value; and 2 if a
  1752.                                       space separates the symbol
  1753.                                       and the sign string,
  1754.                                       if adjacent.
  1755.  
  1756.             "char p_sign_posn"        Value indicating the position
  1757.                                       of the "positive_sign" for a
  1758.                                       non-negative formatted
  1759.                                       monetary quantity.
  1760.  
  1761.             "char n_sign_posn"        Value indicating the position of
  1762.                                       the "negative_sign" for a negative
  1763.                                       formatted monetary quantity.
  1764.  
  1765.  The n_sign_posn and p_sign_posn elements can have the following values: 
  1766.  
  1767.   Value Meaning
  1768.   0  Parentheses surround the quantity and currency_symbol or int_curr_symbol.
  1769.   1  The sign precedes the quantity and currency_symbol or int_curr_symbol.
  1770.   2  The sign follows the quantity and currency_symbol or int_curr_symbol.
  1771.   3  The sign precedes the currency_symbol or int_curr_symbol.
  1772.   4  The sign follows the currency_symbol or int_curr_symbol.
  1773.  
  1774.  The localeconv function returns a pointer to the structure. 
  1775.  Related Information 
  1776.  
  1777.    o  setlocale  - Set Locale 
  1778.    o  locale.h 
  1779.  
  1780.  Example 
  1781.  
  1782.   #include <stdio.h>
  1783.   #include <wchar.h>
  1784.   #include <locale.h>
  1785.  
  1786.   int main(void) {
  1787.       char * string;
  1788.       struct lconv * mylocale;
  1789.       mylocale = localeconv();
  1790.       /* Default decimal point */
  1791.       printf( "Default decimal point is a %s\n",
  1792.            mylocale->decimal_point );
  1793.  
  1794.       string = setlocale(LC_ALL,"Fr_FR");
  1795.       mylocale = localeconv();
  1796.  
  1797.       /*****************************************
  1798.       * A comma is set to be the decimal point *
  1799.       * when the locale is LC_FRANCE           *
  1800.       *****************************************/
  1801.  
  1802.       printf( "France's decimal point is a %s\n", mylocale->decimal_point );
  1803.       }
  1804.  
  1805.   /****************  Output should be similar to:  ******************
  1806.  
  1807.   Default decimal point is a .
  1808.   France's decimal point is a ,
  1809.  
  1810.   *******************************************************************/
  1811.  
  1812.  This example prints out the default decimal point for your locale and then the 
  1813.  decimal point for the LC_FRANCE locale. 
  1814.  
  1815.  
  1816. ΓòÉΓòÉΓòÉ 7.2. MBLEN -- Length in bytes of multi-byte character ΓòÉΓòÉΓòÉ
  1817.  
  1818.  
  1819. Syntax 
  1820.  
  1821. #include <stdlib.h>
  1822. #include <wchar.h>
  1823.  
  1824. int mblen(const char *string, size_t n);
  1825.  
  1826. Description 
  1827.  
  1828. The mblen function determines the length in bytes of the multi-byte character 
  1829. pointed to by string. A maximum of n bytes is examined. 
  1830.  
  1831. If string is NULL, the mblen function returns: 
  1832.  
  1833.    o  Nonzero when encodings have state dependency 
  1834.  
  1835.    o  Zero otherwise. 
  1836.  
  1837.  If string is not NULL, the mblen function returns: 
  1838.  
  1839.    o  Zero if string points to the null character 
  1840.  
  1841.    o  The number of bytes comprising the multi-byte character 
  1842.  
  1843.    o  -1 if string does not point to a valid multi-byte character. 
  1844.  
  1845.  Related Information 
  1846.  
  1847.    o  mbtowc  - Convert multi-byte character to wchar_t 
  1848.    o  mbstowcs  - Convert multi-byte characters to wchar_t characters 
  1849.    o  strlen   - Determine string length 
  1850.    o  wcslen  - Calculate length of wchar_t string 
  1851.    o  wctomb  - Convert wchar_t character to multi-byte character 
  1852.    o  wchar.h 
  1853.  
  1854.  Example 
  1855.  
  1856.   #include <stdio.h>
  1857.   #include <wchar.h>
  1858.  
  1859.   int main(void) {
  1860.       int   length;
  1861.       char *string = "String of multi byte characters";
  1862.  
  1863.       length = mblen(string, MB_CUR_MAX);
  1864.  
  1865.       printf("mblen rc %i  multi-byte character: %c",length,*string);
  1866.       }
  1867.  
  1868.  This example uses mblen to obtain the length of a multi-byte string. 
  1869.  
  1870.  
  1871. ΓòÉΓòÉΓòÉ 7.3. MBSTOWCS -- Converts multi-byte strings to wide-character strings ΓòÉΓòÉΓòÉ
  1872.  
  1873.  
  1874. Syntax 
  1875.  
  1876. #include <stdlib.h>
  1877. #include <wchar.h>
  1878.  
  1879. size_t mbstowcs(wchar_t *pwc, const char *string, size_t n);
  1880.  
  1881. Description 
  1882.  
  1883. The mbstowcs function converts a string of multi-byte characters into a string 
  1884. of wide-characters. No more than n characters will be converted. 
  1885.  
  1886. The mbstowcs function returns the number of wchar_t characters generated not 
  1887. including any terminating zero codes.  If a multi-byte character that is not 
  1888. valid is encountered, the function returns -1. 
  1889. Related Information 
  1890.  
  1891.    o  mblen  - Multi-byte string length 
  1892.    o  mbtowc  - Convert multi-byte character to wchar_t 
  1893.    o  wcslen  - Calculate length of wchar_t string 
  1894.    o  wcstombs  - Convert wchar_t string to multi-byte character string 
  1895.    o  wchar.h 
  1896.  
  1897.  Example 
  1898.  
  1899.   #include <stdio.h>
  1900.   #include <wchar.h>
  1901.  
  1902.   int main(void) {
  1903.       int     rc;
  1904.       char   *string = "String of multi byte characters";
  1905.       wchar_t arr[20];
  1906.  
  1907.       rc = mbstowcs(arr,string,19);
  1908.  
  1909.       printf("\n\nmbstowcs rc %i   wide-character string: %S\n",rc,&arr[0]);
  1910.       }
  1911.  
  1912.  This example uses mbstowcs to convert a multi-byte character string into a 
  1913.  wide-character string. 
  1914.  
  1915.  
  1916. ΓòÉΓòÉΓòÉ 7.4. MBTOWC -- Converts multi-byte character to wide-character ΓòÉΓòÉΓòÉ
  1917.  
  1918.  
  1919. Syntax 
  1920.  
  1921. #include <stdlib.h>
  1922. #include <wchar.h>
  1923.  
  1924. int mbtowc(wchar_t *pwc, const char *string, size_t n);
  1925.  
  1926. Description 
  1927.  
  1928. The mbtowc function first determines the length of the multi-byte character 
  1929. pointed to by string.  It then stores the code for the multi-byte character in 
  1930. the wchar_t object pointed to by pwc.  A maximum of n bytes is examined. 
  1931.  
  1932. If string is NULL, the mbtowc function returns: 
  1933.  
  1934.    o  Nonzero when encodings have state dependency 
  1935.  
  1936.    o  0 otherwise. 
  1937.  
  1938.  If string is not NULL, the mbtowc function returns: 
  1939.  
  1940.    o  0 if string points to the null character 
  1941.  
  1942.    o  The number of bytes comprising the converted multi-byte character 
  1943.  
  1944.    o  -1 if string does not point to a valid multi-byte character. 
  1945.  
  1946.  Related Information 
  1947.  
  1948.    o  mblen  - Multi-byte string length 
  1949.    o  mbstowcs  - Convert multi-byte characters to wchar_t characters 
  1950.    o  wcslen  - Calculate length of wchar_t string 
  1951.    o  wctomb  - Convert wchar_t character to multi-byte character 
  1952.    o  wchar.h 
  1953.  
  1954.  Example 
  1955.  
  1956.   #include <stdio.h>
  1957.   #include <stdlib.h>
  1958.   #include <wchar_t.h>
  1959.  
  1960.   int main(void) {
  1961.       int     rc;
  1962.       char   *string = "ABC";
  1963.       wchar_t arr;
  1964.  
  1965.       rc = mbtowc(&arr,string,MB_CUR_MAX);
  1966.  
  1967.       printf("\nmbtowc rc : %i   wide-character : %C\n",rc,arr);
  1968.       }
  1969.  
  1970.  This example uses mbtowc to convert a multi-byte character into a single 
  1971.  wide-character. 
  1972.  
  1973.  
  1974. ΓòÉΓòÉΓòÉ 7.5. NL_LANGINFO -- Retrieves information about data defined in Locale ΓòÉΓòÉΓòÉ
  1975.  
  1976.  
  1977. Syntax 
  1978.  
  1979. #include <langinfo.h>
  1980.  
  1981. char *nl_langinfo(nl_item item);
  1982.  
  1983. Description 
  1984.  
  1985. The function nl_langinfo returns a character pointer to a string that contains 
  1986. information about the parameter "item" that is supplied by the country's 
  1987. locale.  The values for "item" are defined in the file langinfo.h. 
  1988. Related Information 
  1989.  
  1990.    o  langinfo.h 
  1991.  
  1992.  Example 
  1993.  
  1994.   #include <stdlib.h>
  1995.   #include <stdio.h>
  1996.   #include <langinfo.h>
  1997.   #include <wchar.h>
  1998.   #include <locale.h>
  1999.  
  2000.   int main (void) {
  2001.       printf("\nCalling setlocale\n");
  2002.       printf("Setlocale returns: %s \n", setlocale(LC_ALL, ""));
  2003.  
  2004.       printf("My Kingdom for a Day and a Month : %s %s",
  2005.       nl_langinfo(DAY_5),nl_langinfo(ABMON_10));
  2006.  
  2007.       return(1);
  2008.       }
  2009.  
  2010.  This program queries the current locale for the string which defines the 
  2011.  parameter DAY_5 and ABMON_10. 
  2012.  
  2013.  
  2014. ΓòÉΓòÉΓòÉ 7.6. WCSTOMBS -- Converts a wide-character string to a multi-byte string ΓòÉΓòÉΓòÉ
  2015.  
  2016.  
  2017. Syntax 
  2018.  
  2019. #include <wchar.h>
  2020.  
  2021. size_t wcstombs(char *dest, const wchar_t *ws, size_t count);
  2022.  
  2023. Description. 
  2024.  
  2025. The wcstombs function converts the wchar_t string pointed to by ws into the 
  2026. multi-byte array pointed to by dest. The converted string begins in the initial 
  2027. shift state. The conversion stops after count bytes in dest are filled up or a 
  2028. wchar_t null character is encountered. 
  2029.  
  2030. The wcstombs function returns the length in bytes of the multi-byte character 
  2031. string, not including a terminating null character. The value -1 is returned if 
  2032. an invalid multi-byte character is encountered. 
  2033. Related Information 
  2034.  
  2035.    o  mbstowcs  - Convert multi-byte Characters to wchar_t Characters 
  2036.    o  wcslen  - Calculate Length of wchar_t String 
  2037.    o  wctomb  - Convert wchar_t Character to multi-byte Character 
  2038.    o  wchar.h 
  2039.  
  2040.  Example 
  2041.  
  2042.   #include <stdio.h>
  2043.   #include <stdlib.h>
  2044.   #include <string.h>
  2045.   #include <wchar.h>
  2046.  
  2047.   int main(void) {
  2048.       char dest[20];
  2049.       wchar_t dptr[20];
  2050.       size_t count = 20;
  2051.       size_t length;
  2052.  
  2053.       mbstowcs(dptr,"string",7);
  2054.       length = wcstombs( dest, dptr, count );
  2055.       printf( "%d bytes were converted.\n", length );
  2056.       printf( "The converted string is \"%s\"\n\n", dest );
  2057.  
  2058.       memset( dest, '\0', sizeof(dest));      /* Initialize the buffer */
  2059.  
  2060.       /* Now convert only 3 bytes */
  2061.       length = wcstombs( dest, dptr, 3 );
  2062.  
  2063.       printf( "%d bytes were converted.\n", length );
  2064.       printf( "The converted string is \"%s\"\n", dest );
  2065.       }
  2066.   /****************  Output should be similar to:  ******************
  2067.  
  2068.   12 bytes were converted.
  2069.   The converted string is "string"
  2070.  
  2071.   3 bytes were converted.
  2072.   The converted string is "str"
  2073.  
  2074.   *******************************************************************/
  2075.  
  2076.  In this example, a wchar_t string is converted to a char string twice. The 
  2077.  first call converts the entire string, while the second call only converts 
  2078.  three characters. The results are printed each time. 
  2079.  
  2080.  
  2081. ΓòÉΓòÉΓòÉ 7.7. WCTOMB -- Convert wide character to multibyte character ΓòÉΓòÉΓòÉ
  2082.  
  2083.  
  2084. Syntax 
  2085.  
  2086. #include <wchar.h>
  2087.  
  2088. int wctomb(char *string, wchar_t character);
  2089.  
  2090. Description. 
  2091.  
  2092. The wctomb function converts the wchar_t value of character into a multibyte 
  2093. array pointed to by string.  If the value of character is 0, the function is 
  2094. left in the initial shift state.  At most, wctomb stores MB_CUR_MAX characters 
  2095. in string. 
  2096.  
  2097. The wctomb function returns the length in bytes of the multibyte character. 
  2098. The value -1 is returned if character is not a valid multibyte character.  If 
  2099. string is a NULL pointer, the wctomb function returns nonzero if 
  2100. shift-dependent encoding is used, or 0 otherwise. 
  2101. Related Information 
  2102.  
  2103.    o  mbtowc  - Convert Multibyte Character to wchar_t. 
  2104.    o  wcslen  - Calculate Length of wchar_t String. 
  2105.    o  wcstombs  - Convert wchar_t String to Multibyte Character String. 
  2106.    o  wchar.h - Header file for wide charcter prototypes. 
  2107.  
  2108.  Example 
  2109.  
  2110.   #include <stdio.h>
  2111.   #include <wchar.h>
  2112.  
  2113.   #define SIZE 40
  2114.  
  2115.   int main(void) {
  2116.       static char  buffer[ SIZE ];
  2117.       wchar_t wch = 'c';
  2118.       int length;
  2119.  
  2120.       length = wctomb( buffer, wch );
  2121.  
  2122.       printf( "\nThis multibyte character is (%d) byte(s) long", length);
  2123.       printf( "And the converted string is \"%s\"\n", buffer );
  2124.       }
  2125.  
  2126.  
  2127.   /****************  Output should be similar to:  ******************
  2128.  
  2129.   This multibyte character is 1 byte(s) long
  2130.   And the converted string is "c"
  2131.  
  2132.   *******************************************************************/
  2133.  
  2134.  This example converts the wide character c to a character. 
  2135.  
  2136.  
  2137. ΓòÉΓòÉΓòÉ 8. Formatted I/O Functions ΓòÉΓòÉΓòÉ
  2138.  
  2139.  
  2140. ΓòÉΓòÉΓòÉ 8.1. FPRINTF -- Formats output to an output stream ΓòÉΓòÉΓòÉ
  2141.  
  2142.  
  2143. Syntax 
  2144.  
  2145. #include <stdio.h>
  2146.  
  2147. int fprintf(FILE *stream, const char *format-string, argument-list);
  2148.  
  2149. Description 
  2150.  
  2151. The fprintf function formats and writes a series of characters and values to 
  2152. the output stream.  The fprintf function converts each entry in argument-list, 
  2153. if any, and writes to the stream according to the corresponding format 
  2154. specification in the format-string. 
  2155.  
  2156. The format-string has the same form and function as the format-string argument 
  2157. for the printf function. 
  2158.  
  2159. In extended mode, fprintf also converts floating-point values of NaN and 
  2160. infinity to the strings "NAN" or "nan" and "INFINITY" or "infinity". The case 
  2161. and sign of the string is determined by the format specifiers.  See Infinity 
  2162. and NaN Support for more information on infinity and NaN values. 
  2163.  
  2164. The fprintf function returns the number of characters printed or a negative 
  2165. value if an output error occurs. 
  2166. Related Information 
  2167.  
  2168.    o  fscanf  - Read Formatted Data. 
  2169.    o  printf  - Formatted Print. 
  2170.    o  sprintf  - Formatted Print to Buffer. 
  2171.    o  stdio.h  - Include file for standard I/O functions. 
  2172.  
  2173.  Example 
  2174.  
  2175.   #include <stdio.h>
  2176.   #include <wchar.h>
  2177.  
  2178.   #define MAXLEN  80
  2179.  
  2180.   int main(void) {
  2181.       int count;
  2182.       FILE *stream;
  2183.       long l;
  2184.       float fp;
  2185.       wchar_t s[MAXLEN];
  2186.       wchar_t c[MAXLEN];
  2187.  
  2188.       fp = 1.34e-2;
  2189.  
  2190.       l = 1000000;
  2191.  
  2192.       mbstowcs(s,"ABCDEFGHIJKLMNOPQRSTUVWXYZ",MAXLEN);
  2193.       mbstowcs(c,"A",MAXLEN);
  2194.  
  2195.       stream = fopen("myfile.dat", "w");
  2196.  
  2197.       fprintf(stream, "%S", s);
  2198.       fprintf(stream, "%ld", l);
  2199.       fprintf(stream, "%C", c[0]);
  2200.       fprintf(stream, "%f", fp);
  2201.  
  2202.       printf("\n");
  2203.  
  2204.       fclose(stream);
  2205.       }
  2206.  
  2207.  This example stores a series of data types to a file "myfile.dat" using the 
  2208.  fprintf function. 
  2209.  
  2210.  
  2211. ΓòÉΓòÉΓòÉ 8.2. FSCANF -- Reads data from a stream and returns data to argument list ΓòÉΓòÉΓòÉ
  2212.  
  2213.  
  2214. Syntax 
  2215.  
  2216. #include <stdio.h> /* when using C set 2 the header file is <wchar.h> */
  2217.  
  2218. int fscanf (FILE *stream, const char *format-string, argument-list);
  2219.  
  2220. Description 
  2221.  
  2222. The fscanf function reads data from the current position of the specified 
  2223. stream into the locations given by the entries in argument-list, if any.  Each 
  2224. entry in argument-list must be a pointer to a variable with a type that 
  2225. corresponds to a type specifier in format-string. 
  2226.  
  2227. The format-string controls the interpretation of the input fields and has the 
  2228. same form and function as the format-string argument for the scanf function. 
  2229. See scanf for a description of format-string. 
  2230.  
  2231. In extended mode, the fscanf function also reads in the strings "INFINITY", 
  2232. "INF", and "NAN" (in upper or lowercase) and converts them to the corresponding 
  2233. floating-point value.  The sign of the value is determined by the format 
  2234. specification. See Infinity and NaN Support for more information on infinity 
  2235. and NaN values. 
  2236.  
  2237. The fscanf function returns the number of fields that it successfully converted 
  2238. and assigned.  The return value does not include fields that fscanf read but 
  2239. did not assign. 
  2240.  
  2241. The return value is ether an EOF if an input failure occurs before any 
  2242. conversion, or the number of input items assigned successfully converted.  If 
  2243. EOF is returned then errno maybe checked for additional information. 
  2244.  
  2245. New Formatting Codes.  Using the n$ feature the order of arguments referenced 
  2246. can be changed. For example in the following statment: fscanf(stream,"%d 
  2247. %d",&value1, &value2);  By using the n$ format the value2 could be referenced 
  2248. before value1.  For example: fscanf(stream,"%2$d %1$d",&value1,&value2).  The 
  2249. %S is used to print wide character strings for wide character support.  The %C 
  2250. is used to print individual wide characters for wide character support. 
  2251. Related Information 
  2252.  
  2253.    o  fprintf  - Write Formatted Data 
  2254.    o  scanf  - Read Data 
  2255.    o  stdio.h  - Normal location for fscanf function prototype, 
  2256.       however for this implementation uses wchar.h. 
  2257.    o  wchar.h  - Header file for wide character support. 
  2258.  
  2259.  Example 
  2260.  
  2261.   #include <stdio.h>
  2262.   #include <stdlib.h>
  2263.   #include <wchar.h>
  2264.  
  2265.   #define MAXLEN  80
  2266.  
  2267.   int main(void) {
  2268.       int count;
  2269.       FILE *stream;
  2270.       long l;
  2271.       float fp;
  2272.       wchar_t s[MAXLEN];
  2273.       wchar_t c;
  2274.  
  2275.       for(count=0;count<MAXLEN;count++){s[count]=0;};
  2276.  
  2277.       stream = fopen("myfile.dat", "r");
  2278.  
  2279.       fscanf(stream, "%26C", &s);
  2280.       fscanf(stream, "%ld", &l);
  2281.       fscanf(stream, "%C", &c);
  2282.       fscanf(stream, "%f", &fp);
  2283.  
  2284.       printf("string = %S\n", s);
  2285.       printf("long double = %ld\n", l);
  2286.       printf("char = %C\n", c);
  2287.       printf("float = %f\n", fp);
  2288.  
  2289.       printf("\n");
  2290.  
  2291.       fclose(stream);
  2292.       }
  2293.  
  2294.  
  2295.   /***************  If myfile.dat contains  ********************
  2296.  
  2297.            ABCDEFGHIJKLMNOPQRSTUVWXYZ1000000A0.013400
  2298.  
  2299.   *******************  expected output is:  ********************
  2300.  
  2301.   string = ABCDEFGHIJKLMNOPQRSTUVWXYZ
  2302.   long double = 1000000
  2303.   char = A
  2304.   float = 0.013400
  2305.  
  2306.   **************************************************************/
  2307.  
  2308.  This example opens the file myfile.dat for reading and then scans this file 
  2309.  for a string, a long integer value, a character, and a floating-point value. 
  2310.  
  2311.  
  2312. ΓòÉΓòÉΓòÉ 8.3. PRINTF -- Format and print characters ΓòÉΓòÉΓòÉ
  2313.  
  2314.  
  2315. Syntax 
  2316.  
  2317. #include <stdio.h>
  2318. #include <wchar.h>
  2319.  
  2320. int printf(const char *format-string, ...);
  2321.  
  2322. Description 
  2323.  
  2324. The printf function formats and prints a series of characters and values to the 
  2325. standard output stream stdout.  The format-string consists of ordinary 
  2326. characters, escape sequences, and format specifications.  The ordinary 
  2327. characters are copied in order of their appearance to stdout.  Format 
  2328. specifications, beginning with a percent sign (%), determine the output format 
  2329. for any argument-list following the format-string.  The format-string is a 
  2330. multibyte character string beginning and ending in its initial shift state. 
  2331.  
  2332. The format-string is read left to right.  When the first format specification 
  2333. is found, the value of the first argument after the format-string is converted 
  2334. and output according to the format specification.  The second format 
  2335. specification causes the second argument after the format-string to be 
  2336. converted and output, and so on through the end of the format-string.  If there 
  2337. are more arguments than there are format specifications, the extra arguments 
  2338. are evaluated and ignored.  The results are undefined if there are not enough 
  2339. arguments for all the format specifications.  A format specification has the 
  2340. following form: 
  2341.  
  2342.  
  2343.  
  2344.  ΓöÇΓöÇ%ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇtypeΓöÇΓöÇ
  2345.         Γöé         Γöé  Γöé         Γöé  Γöé                Γöé  Γöé     Γöé
  2346.         ΓööΓöÇΓöÇflagsΓöÇΓöÇΓöÿ  ΓööΓöÇΓöÇwidthΓöÇΓöÇΓöÿ  ΓööΓöÇΓöÇ.ΓöÇΓöÇprecisionΓöÇΓöÇΓöÿ  Γö£ΓöÇΓöÇhΓöÇΓöÇΓöñ
  2347.                                                       Γöé     Γöé
  2348.                                                       Γö£ΓöÇΓöÇLΓöÇΓöÇΓöñ
  2349.                                                       Γöé     Γöé
  2350.                                                       ΓööΓöÇΓöÇlΓöÇΓöÇΓöÿ
  2351.  
  2352. Each field of the format specification is a single character or number 
  2353. signifying a particular format option.  The type character, which appears after 
  2354. the last optional format field, determines whether the associated argument is 
  2355. interpreted as a character, a string, a number, or pointer.  The simplest 
  2356. format specification contains only the percent sign and a type character (for 
  2357. example, %s). 
  2358.  
  2359. The following optional fields control other aspects of the formatting: 
  2360.  
  2361. Field       Description
  2362.  
  2363. flags       Justification of output and printing of signs, blanks,
  2364.             decimal points, octal, and hexadecimal prefixes, and the
  2365.             semantics for wchar_t precision unit.
  2366.  
  2367. width       Minimum number of characters (bytes) output.
  2368.  
  2369. precision   Maximum number of characters (bytes) printed for all or
  2370.             part of the output field, or minimum number of digits
  2371.             printed for integer values.
  2372.  
  2373. h,l,L       Size of argument expected.
  2374.  
  2375. The type characters and their meanings are given in the following table: 
  2376.  
  2377. ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  2378. Γöé CHAR- Γöé ARGUMENT   Γöé OUTPUT FORMAT                             Γöé
  2379. Γöé ACTER Γöé            Γöé                                           Γöé
  2380. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  2381. Γöé d, i  Γöé Integer    Γöé Signed decimal integer.                   Γöé
  2382. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  2383. Γöé u     Γöé Integer    Γöé Unsigned decimal integer.                 Γöé
  2384. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  2385. Γöé o     Γöé Integer    Γöé Unsigned octal integer.                   Γöé
  2386. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  2387. Γöé x     Γöé Integer    Γöé Unsigned hexadecimal integer, using       Γöé
  2388. Γöé       Γöé            Γöé abcdef.                                   Γöé
  2389. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  2390. Γöé X     Γöé Integer    Γöé Unsigned hexadecimal integer, using       Γöé
  2391. Γöé       Γöé            Γöé ABCDEF.                                   Γöé
  2392. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  2393. Γöé f     Γöé Double     Γöé Signed value having the form              Γöé
  2394. Γöé       Γöé            Γöé [-]dddd.dddd, where dddd is one or more   Γöé
  2395. Γöé       Γöé            Γöé decimal digits.  The number of digits     Γöé
  2396. Γöé       Γöé            Γöé before the decimal point depends on the   Γöé
  2397. Γöé       Γöé            Γöé magnitude of the number.  The number of   Γöé
  2398. Γöé       Γöé            Γöé digits after the decimal point is equal   Γöé
  2399. Γöé       Γöé            Γöé to the requested precision.               Γöé
  2400. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  2401. Γöé e     Γöé Double     Γöé Signed value having the form              Γöé
  2402. Γöé       Γöé            Γöé [-]d.dddd"e"[sign]ddd, where d is a       Γöé
  2403. Γöé       Γöé            Γöé single-decimal digit, dddd is one or more Γöé
  2404. Γöé       Γöé            Γöé decimal digits, ddd is 2 or more decimal  Γöé
  2405. Γöé       Γöé            Γöé digits, and sign is + or -.               Γöé
  2406. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  2407. Γöé E     Γöé Double     Γöé Identical to the "e" format except that   Γöé
  2408. Γöé       Γöé            Γöé "E" introduces the exponent instead of    Γöé
  2409. Γöé       Γöé            Γöé "e".                                      Γöé
  2410. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  2411. Γöé g     Γöé Double     Γöé Signed value printed in "f" or "e"        Γöé
  2412. Γöé       Γöé            Γöé format.  The "e" format is used only when Γöé
  2413. Γöé       Γöé            Γöé the exponent of the value is less than -4 Γöé
  2414. Γöé       Γöé            Γöé or greater than precision.  Trailing      Γöé
  2415. Γöé       Γöé            Γöé zeros are truncated, and the decimal      Γöé
  2416. Γöé       Γöé            Γöé point appears only if one or more digits  Γöé
  2417. Γöé       Γöé            Γöé follow it.                                Γöé
  2418. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  2419. Γöé G     Γöé Double     Γöé Identical to the "g" format except that   Γöé
  2420. Γöé       Γöé            Γöé "E" introduces the exponent (where appro- Γöé
  2421. Γöé       Γöé            Γöé priate) instead of "e".                   Γöé
  2422. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  2423. Γöé c     Γöé Character  Γöé Single character.                         Γöé
  2424. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  2425. Γöé s     Γöé String     Γöé Characters printed up to the first null   Γöé
  2426. Γöé       Γöé            Γöé character (\"0") or until precision is    Γöé
  2427. Γöé       Γöé            Γöé reached.                                  Γöé
  2428. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  2429. Γöé n     Γöé Pointer to Γöé Number of characters successfully written Γöé
  2430. Γöé       Γöé integer    Γöé so far to the stream or buffer; this      Γöé
  2431. Γöé       Γöé            Γöé value is stored in the integer whose      Γöé
  2432. Γöé       Γöé            Γöé address is given as the argument.         Γöé
  2433. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  2434. Γöé p     Γöé Pointer    Γöé Pointer to void converted to a sequence   Γöé
  2435. Γöé       Γöé            Γöé of printable characters.                  Γöé
  2436. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  2437. Γöé "lc"  Γöé Wide char- Γöé Multibyte character.                      Γöé
  2438. Γöé       Γöé acter      Γöé                                           Γöé
  2439. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  2440. Γöé "ls"  Γöé Wide       Γöé Multibyte characters printed up to the    Γöé
  2441. Γöé       Γöé string     Γöé first "wchar_t" null character ("L\0") or Γöé
  2442. Γöé       Γöé            Γöé until precision is reached.               Γöé
  2443. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  2444. Γöé C     Γöé Wide char- Γöé A wchar_t character is converted into an  Γöé
  2445. Γöé       Γöé acter to   Γöé array of characters representing an multi Γöé
  2446. Γöé       Γöé Multibyte  Γöé byte character and this character is      Γöé
  2447. Γöé       Γöé            Γöé printed out.  Same result as wctomb().    Γöé
  2448. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  2449. Γöé S     Γöé Wide char- Γöé Takes a pointer to an array of wchar_t    Γöé
  2450. Γöé       Γöé acter str- Γöé characters and converts it to an array of Γöé
  2451. Γöé       Γöé ing to     Γöé multibyte characters upto but not         Γöé
  2452. Γöé       Γöé Multibyte  Γöé including the null character and prints   Γöé
  2453. Γöé       Γöé String     Γöé the result.  Same result as wcstombs().   Γöé
  2454. ΓööΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ
  2455.  
  2456. The flag characters and their meanings are as follows (notice that more than 
  2457. one flag can appear in a format specification): 
  2458.  
  2459. ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  2460. Γöé FLAG      Γöé MEANING                     Γöé DEFAULT              Γöé
  2461. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  2462. Γöé -         Γöé Left-justify the result     Γöé Right-justify.       Γöé
  2463. Γöé           Γöé within the field width.     Γöé                      Γöé
  2464. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  2465. Γöé +         Γöé Prefix the output value     Γöé Sign appears only    Γöé
  2466. Γöé           Γöé with a sign (+ or -) if the Γöé for negative signed  Γöé
  2467. Γöé           Γöé output value is of a signed Γöé values (-).          Γöé
  2468. Γöé           Γöé type.                       Γöé                      Γöé
  2469. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  2470. Γöé blank(' ')Γöé Prefix the output value     Γöé No blank.            Γöé
  2471. Γöé           Γöé with a blank if the output  Γöé                      Γöé
  2472. Γöé           Γöé value is signed and posi-   Γöé                      Γöé
  2473. Γöé           Γöé tive.  The "+" flag over-   Γöé                      Γöé
  2474. Γöé           Γöé rides the blank flag if     Γöé                      Γöé
  2475. Γöé           Γöé both appear, and a positive Γöé                      Γöé
  2476. Γöé           Γöé signed value will be output Γöé                      Γöé
  2477. Γöé           Γöé with a sign.                Γöé                      Γöé
  2478. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  2479. Γöé #         Γöé When used with the "o",     Γöé No prefix.           Γöé
  2480. Γöé           Γöé "x", or "X" formats, the    Γöé                      Γöé
  2481. Γöé           Γöé "#" flag prefixes any       Γöé                      Γöé
  2482. Γöé           Γöé nonzero output value with   Γöé                      Γöé
  2483. Γöé           Γöé "0", "0"x, or "0"X, respec- Γöé                      Γöé
  2484. Γöé           Γöé tively.                     Γöé                      Γöé
  2485. Γöé           Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  2486. Γöé           Γöé When used with the "f",     Γöé Decimal point        Γöé
  2487. Γöé           Γöé "e", or "E" formats, the    Γöé appears only if      Γöé
  2488. Γöé           Γöé "#" flag forces the output  Γöé digits follow it.    Γöé
  2489. Γöé           Γöé value to contain a decimal  Γöé                      Γöé
  2490. Γöé           Γöé point in all cases.         Γöé                      Γöé
  2491. Γöé           Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  2492. Γöé           Γöé When used with the "g" or   Γöé Decimal point        Γöé
  2493. Γöé           Γöé "G" formats, the "#" flag   Γöé appears only if      Γöé
  2494. Γöé           Γöé forces the output value to  Γöé digits follow it;    Γöé
  2495. Γöé           Γöé contain a decimal point in  Γöé trailing zeros are   Γöé
  2496. Γöé           Γöé all cases and prevents the  Γöé truncated.           Γöé
  2497. Γöé           Γöé truncation of trailing      Γöé                      Γöé
  2498. Γöé           Γöé zeros.                      Γöé                      Γöé
  2499. Γöé           Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  2500. Γöé           Γöé When used with the "ls"     Γöé Precision indicates  Γöé
  2501. Γöé           Γöé format, the "#" flag causes Γöé the maximum number   Γöé
  2502. Γöé           Γöé precision to be measured in Γöé of bytes to be       Γöé
  2503. Γöé           Γöé "wchar_t" characters.       Γöé output.              Γöé
  2504. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  2505. Γöé "0"       Γöé When used with the "d",     Γöé Space padding.       Γöé
  2506. Γöé           Γöé "i", "o", "u", "x", "X",    Γöé                      Γöé
  2507. Γöé           Γöé "e", "E", "f", "g", or "G"  Γöé                      Γöé
  2508. Γöé           Γöé formats, the "0" flag       Γöé                      Γöé
  2509. Γöé           Γöé causes leading "0"'s to pad Γöé                      Γöé
  2510. Γöé           Γöé the output to the field     Γöé                      Γöé
  2511. Γöé           Γöé width.  The "0" flag is     Γöé                      Γöé
  2512. Γöé           Γöé ignored if precision is     Γöé                      Γöé
  2513. Γöé           Γöé specified for an integer or Γöé                      Γöé
  2514. Γöé           Γöé if the "-" flag is speci-   Γöé                      Γöé
  2515. Γöé           Γöé fied.                       Γöé                      Γöé
  2516. ΓööΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ
  2517.  
  2518. The # flag should not be used with c, lc, d, i, u, s, or p types. 
  2519.  
  2520. Width is a nonnegative decimal integer controlling the minimum number of 
  2521. characters printed.  If the number of characters in the output value is less 
  2522. than the specified width, blanks are added on the left or the right (depending 
  2523. on whether the - flag is specified) until the minimum width is reached. 
  2524.  
  2525. Width never causes a value to be truncated;  if the number of characters in the 
  2526. output value is greater than the specified width, or width is not given, all 
  2527. characters of the value are printed ( subject to the precision specification). 
  2528.  
  2529. For the ls type, width is specified in bytes. If the number of bytes in the 
  2530. output value is less than the specified width, single-byte blanks are added on 
  2531. the left or the right (depending on whether the - flag is specified) until the 
  2532. minimum width is reached. 
  2533.  
  2534. The width specification can be an asterisk (*), in which case an argument from 
  2535. the argument list supplies the value.  The width argument must precede the 
  2536. value being formatted in the argument list. 
  2537.  
  2538. Precision is a nonnegative decimal integer preceded by a period, which 
  2539. specifies the number of characters to be printed or the number of decimal 
  2540. places.  Unlike the width specification, the precision can cause truncation of 
  2541. the output value or rounding of a floating-point value. 
  2542.  
  2543. The precision specification can be an asterisk (*), in which case an argument 
  2544. from the argument list supplies the value.  The precision argument must precede 
  2545. the value being formatted in the argument list. 
  2546.  
  2547. The interpretation of the precision value and the default when the precision is 
  2548. omitted depend upon the type, as shown in the following table: 
  2549.  
  2550. ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  2551. Γöé TYPE  Γöé MEANING                         Γöé DEFAULT              Γöé
  2552. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  2553. Γöé    i  Γöé Precision specifies the minimum Γöé If precision is "0"  Γöé
  2554. Γöé    d  Γöé number of digits to be printed. Γöé or omitted entirely, Γöé
  2555. Γöé    u  Γöé If the number of digits in the  Γöé or if the period (.) Γöé
  2556. Γöé    o  Γöé argument is less than           Γöé appears without a    Γöé
  2557. Γöé    x  Γöé precision, the output value is  Γöé number following it, Γöé
  2558. Γöé    X  Γöé padded on the left with zeros.  Γöé the precision is set Γöé
  2559. Γöé       Γöé The value is not truncated when Γöé to 1.                Γöé
  2560. Γöé       Γöé the number of digits exceeds    Γöé                      Γöé
  2561. Γöé       Γöé precision.                      Γöé                      Γöé
  2562. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  2563. Γöé    f  Γöé Precision specifies the number  Γöé Default precision is Γöé
  2564. Γöé    e  Γöé of digits to be printed after   Γöé six.  If precision   Γöé
  2565. Γöé    E  Γöé the decimal point.  The last    Γöé is "0" or the period Γöé
  2566. Γöé       Γöé digit printed is rounded.       Γöé appears without a    Γöé
  2567. Γöé       Γöé                                 Γöé number following it, Γöé
  2568. Γöé       Γöé                                 Γöé no decimal point is  Γöé
  2569. Γöé       Γöé                                 Γöé printed.             Γöé
  2570. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  2571. Γöé    g  Γöé Precision specifies the maximum Γöé All significant      Γöé
  2572. Γöé    G  Γöé number of significant digits    Γöé digits are printed.  Γöé
  2573. Γöé       Γöé printed.                        Γöé                      Γöé
  2574. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  2575. Γöé    c  Γöé No effect.                      Γöé The character is     Γöé
  2576. Γöé       Γöé                                 Γöé printed.             Γöé
  2577. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  2578. Γöé    lc Γöé No effect.                      Γöé The "wchar_t" char-  Γöé
  2579. Γöé       Γöé                                 Γöé acter is printed.    Γöé
  2580. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  2581. Γöé    s  Γöé Precision specifies the maximum Γöé Characters are       Γöé
  2582. Γöé       Γöé number of characters to be      Γöé printed until a null Γöé
  2583. Γöé       Γöé printed.  Characters in excess  Γöé character is         Γöé
  2584. Γöé       Γöé of precision are not printed.   Γöé encountered.         Γöé
  2585. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  2586. Γöé    ls Γöé Precision specifies the maximum Γöé "wchar_t" characters Γöé
  2587. Γöé       Γöé number of bytes to be printed.  Γöé are printed until a  Γöé
  2588. Γöé       Γöé Bytes in excess of precision    Γöé null character is    Γöé
  2589. Γöé       Γöé are not printed; however,       Γöé encountered.         Γöé
  2590. Γöé       Γöé multibyte integrity is always   Γöé                      Γöé
  2591. Γöé       Γöé preserved.                      Γöé                      Γöé
  2592. ΓööΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ
  2593.  
  2594. The h, l, and L characters specify the size of the expected argument.  Their 
  2595. meanings are as follows: h   A prefix with the integer types d, i, o, u, x, X, 
  2596. and n    that specifies that the argument is short int or    unsigned short 
  2597. int.  l   A prefix with d, i, o, u, x, X, and n types that    specifies that 
  2598. the argument is a long int or    unsigned long int.  L   A prefix with e, E, f, 
  2599. g, or G types that specifies that    the argument is long double. 
  2600.  
  2601. If a percent sign (%) is followed by a character that has no meaning as a 
  2602. format field, the character is simply copied to stdout.  For example, to print 
  2603. a percent sign character, use %%. 
  2604.  
  2605. The printf function returns the number of characters (bytes) printed. 
  2606. Related Information 
  2607.  
  2608.    o  fprintf  - Write Formatted Data 
  2609.    o  fscanf  - Read Formatted Data 
  2610.    o  scanf  - Read Data 
  2611.    o  sprintf  - Formatted Print to Buffer 
  2612.    o  sscanf  - Read Data 
  2613.    o  stdio.h 
  2614.  
  2615.  Example 
  2616.  
  2617.   #include <stdio.h>
  2618.   #include <wchar.h>
  2619.  
  2620.   int main(void) {
  2621.       char ch = 'h', *string = "computer";
  2622.       int count = 234, hex = 0x10, oct = 010, dec = 10;
  2623.       double fp = 251.7366;
  2624.       wchar_t wc = (wchar_t)0x0058;
  2625.       wchar_t ws[4];
  2626.  
  2627.       ws[0] = (wchar_t)0x0041;
  2628.       ws[1] = (wchar_t)0x0042;
  2629.       ws[2] = (wchar_t)0x0043;
  2630.       ws[3] = (wchar_t)0x0000;
  2631.  
  2632.       printf("%d   %+d    %06d     %X    %x     %o\n\n",
  2633.           count, count, count, count, count, count);
  2634.  
  2635.       printf("1234567890123%n4567890123456789\n\n", &count);
  2636.       printf("Value of count should be 13; count = %d\n\n", count);
  2637.       printf("%10c%5c\n", ch, ch);
  2638.       printf("%25s\n%25.4s\n\n", string, string);
  2639.       printf("%f    %.2f    %e    %E\n\n", fp, fp, fp, fp);
  2640.       printf("%i    %i     %i\n\n", hex, oct, dec);
  2641.       printf("%C    %S\n\n",wc,ws);
  2642.       printf("%2$C    %1$2S\n\n",ws,wc);
  2643.       }
  2644.  
  2645.   /*****************  Output should be similar to:  *****************
  2646.  
  2647.   234   +234    000234     EA    ea     352
  2648.  
  2649.   12345678901234567890123456789
  2650.  
  2651.   Value of count should be 13; count = 13
  2652.  
  2653.     h    h
  2654.             computer
  2655.                 comp
  2656.  
  2657.   251.736600    251.74    2.517366e+02    2.517366E+02
  2658.  
  2659.   16    8     10
  2660.  
  2661.   X     ABC
  2662.  
  2663.   X     AB
  2664.  
  2665.   *******************************************************************/
  2666.  
  2667.  This example prints data in a variety of formats. 
  2668.  
  2669.  
  2670. ΓòÉΓòÉΓòÉ 8.4. SCANF -- Reads formatted data from the standard input ΓòÉΓòÉΓòÉ
  2671.  
  2672.  
  2673. Syntax 
  2674.  
  2675. #include <stdio.h>
  2676. #include <wchar.h>
  2677.  
  2678. int scanf(const char *format-string, argument-list);
  2679.  
  2680. Description 
  2681.  
  2682. The scanf function reads data from the standard input stream stdin into the 
  2683. locations given by each entry in argument-list. Each argument must be a pointer 
  2684. to a variable with a type that corresponds to a type specifier in 
  2685. format-string.  The format-string controls the interpretation of the input 
  2686. fields, and is a multibyte character string beginning and ending in its initial 
  2687. shift state. 
  2688.  
  2689. The format-string can contain one or more of the following: 
  2690.  
  2691.    o  White-space characters, as specified by isspace (such as blanks and 
  2692.       new-line characters). A white-space character causes scanf to read, but 
  2693.       not to store, all consecutive white-space characters in the input up to 
  2694.       the next character that is not white-space.  One white-space character in 
  2695.       format-string matches any combination of white-space characters in the 
  2696.       input. 
  2697.  
  2698.    o  Characters that are not white space, except for the percent sign 
  2699.       character (%).  A non-white-space character causes scanf to read, but not 
  2700.       to store, a matching non-white-space character.  If the next character in 
  2701.       stdin does not match, scanf ends. 
  2702.  
  2703.    o  Format specifications, introduced by the percent sign (%).  A format 
  2704.       specification causes scanf to read and convert characters in the input 
  2705.       into values of a specified type.  The value is assigned to an argument in 
  2706.       the argument list. 
  2707.  
  2708.  The scanf function reads format-string from left to right. Characters outside 
  2709.  of format specifications are expected to match the sequence of characters in 
  2710.  stdin;  the matched characters in stdin are scanned but not stored.  If a 
  2711.  character in stdin conflicts with format-string, scanf ends.  The conflicting 
  2712.  character is left in stdin as if it had no been read. 
  2713.  
  2714.  When the first format specification is found, the value of the first input 
  2715.  field is converted according to the format specification and stored in the 
  2716.  location specified by the first entry in argument-list. The second format 
  2717.  specification converts the second input field and stores it in the second 
  2718.  entry in argument-list, and so on through the end of format-string. 
  2719.  
  2720.  An input field is defined as all characters up to the first white-space 
  2721.  character (space, tab, or new line), up to the first character that cannot be 
  2722.  converted according to the format specification, or until the field width is 
  2723.  reached, whichever comes first.  If there are too many arguments for the 
  2724.  format specifications, the extra arguments are ignored.  The results are 
  2725.  undefined if there are not enough arguments for the format specifications. 
  2726.  
  2727.  A format specification has the following form: 
  2728.  
  2729.  
  2730.  
  2731.    ΓöÇΓöÇ%ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇtypeΓöÇΓöÇ
  2732.           Γöé     Γöé  Γöé         Γöé  Γöé     Γöé
  2733.           ΓööΓöÇΓöÇ*ΓöÇΓöÇΓöÿ  ΓööΓöÇΓöÇwidthΓöÇΓöÇΓöÿ  Γö£ΓöÇΓöÇhΓöÇΓöÇΓöñ
  2734.                                 Γöé     Γöé
  2735.                                 Γö£ΓöÇΓöÇlΓöÇΓöÇΓöñ
  2736.                                 Γöé     Γöé
  2737.                                 ΓööΓöÇΓöÇLΓöÇΓöÇΓöÿ
  2738.  
  2739.  Each field of the format specification is a single character or a number 
  2740.  signifying a particular format option.  The type character, which appears 
  2741.  after the last optional format field, determines whether the input field is 
  2742.  interpreted as a character, a string, or a number.  The simplest format 
  2743.  specification contains only the percent sign and a type character (for 
  2744.  example, %s). 
  2745.  
  2746.  Each field of the format specification is discussed in SCANF Format Tags. If a 
  2747.  percent sign (%) is followed by a character that has no meaning as a format 
  2748.  control character, that character and following characters up to the next 
  2749.  percent sign are treated as an ordinary sequence of characters;  that is, a 
  2750.  sequence of characters that must match the input.  For example, to specify a 
  2751.  percent-sign character, use %%. 
  2752.  
  2753.  The scanf function scans each input field character by character. It might 
  2754.  stop reading a particular input field either before it reaches a space 
  2755.  character, when the specified width is reached, or when the next character 
  2756.  cannot be converted as specified.  When a conflict occurs between the 
  2757.  specification and the input character, the next input field begins at the 
  2758.  first unread character.  The conflicting character, if there was one, is 
  2759.  considered unread and is the first character of the next input field or the 
  2760.  first character in subsequent read operations on stdin. 
  2761.  
  2762.  The scanf function returns the number of fields that were successfully 
  2763.  converted and assigned.  The return value does not include fields that were 
  2764.  read but not assigned. 
  2765.  
  2766.  The return value is EOF for an attempt to read at end-of-file if no conversion 
  2767.  was performed. A return value of 0 means that no fields were assigned. 
  2768.  Related Information 
  2769.  
  2770.    o  fscanf  - Read Formatted Data 
  2771.    o  printf  - Formatted Print 
  2772.    o  sscanf  - Read Data 
  2773.    o  wchar.h 
  2774.  
  2775.  Example 
  2776.  
  2777.   #include <wchar.h>
  2778.  
  2779.   int main(void) {
  2780.       int i;
  2781.       float fp;
  2782.       char c, s[81];
  2783.       wchar_t wc;
  2784.       wchar_t ws[81];
  2785.  
  2786.       printf("Enter an integer, a real number, a character, a string,\n"
  2787.          "a multi-byte character, and a multi-byte string : \n");
  2788.  
  2789.       if (scanf("%d %f %c %s %C %S", &i, &fp, &c, s, &wc, ws) != 6)
  2790.         printf("Not all of the fields were assigned\n");
  2791.       else {
  2792.         printf("integer = %d\n", i);
  2793.         printf("real number = %f\n", fp);
  2794.         printf("character = %c\n", c);
  2795.         printf("string = %s\n",s);
  2796.         printf("wide-character = %C\n", wc);
  2797.         printf("wide-character string = %S\n",ws);
  2798.         }
  2799.       }
  2800.  
  2801.  
  2802.   /*****************  If input is: 12 2.5 a yes,  *******************
  2803.   **************  then output should be similar to:  ****************
  2804.  
  2805.   Enter an integer, a real number, a character and a string :
  2806.   integer = 12
  2807.   real number = 2.500000
  2808.   character = a
  2809.   string = yes
  2810.  
  2811.   *******************************************************************/
  2812.  
  2813.  This example scans various types of data: 
  2814.  SCANF Format Tags 
  2815.  
  2816.  The scanf format specification fields are described below. 
  2817.  
  2818.   *
  2819.  An asterisk (*) following the percent sign suppresses assignment of the next 
  2820.  input field, which is interpreted as a field of the specified type.  The field 
  2821.  is scanned but not stored. 
  2822.  
  2823.   width
  2824.  
  2825.  The width is a positive decimal integer controlling the maximum number of 
  2826.  characters to be read from stdin. No more than width characters are converted 
  2827.  and stored at the corresponding argument.  Fewer than width characters are 
  2828.  read if a white-space character (space, tab, or new line), or a character that 
  2829.  cannot be converted according to the given format occurs before width is 
  2830.  reached. 
  2831.  
  2832.   h, l, L
  2833.  
  2834.  The optional prefix l(ell) shows that you use the long version of the 
  2835.  following type, while the prefix h indicates that the short version is to be 
  2836.  used.  The corresponding argument should point to a long or double object (for 
  2837.  the l character), a long double object (for the L character), or a short 
  2838.  object (with the h character).  The l and h modifiers can be used with the d, 
  2839.  i, o, x, and u type characters. The l modifier can also be used with the e, f, 
  2840.  and g type characters.  The L modifier can be used with the e, f and g type 
  2841.  characters. The l and h modifiers are ignored if specified for any other type. 
  2842.  Note that the l modifier is also used with the c and s characters to indicate 
  2843.  a multibyte character or string. 
  2844.  
  2845.   type
  2846.  
  2847.  The type characters and their meanings are in the following table: 
  2848.  
  2849.   ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  2850.   Γöé CHAR-  Γöé TYPE OF INPUT EXPECTED    Γöé TYPE OF ARGUMENT          Γöé
  2851.   Γöé ACTER  Γöé                           Γöé                           Γöé
  2852.   Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  2853.   Γöé "d"    Γöé Decimal integer           Γöé Pointer to "int"          Γöé
  2854.   Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  2855.   Γöé "o"    Γöé Octal integer             Γöé Pointer to "unsigned int" Γöé
  2856.   Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  2857.   Γöé "x",   Γöé Hexadecimal integer       Γöé Pointer to "unsigned int" Γöé
  2858.   Γöé "X"    Γöé                           Γöé                           Γöé
  2859.   Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  2860.   Γöé "i"    Γöé Decimal, hexadecimal, or  Γöé Pointer to "int"          Γöé
  2861.   Γöé        Γöé octal integer             Γöé                           Γöé
  2862.   Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  2863.   Γöé "u"    Γöé Unsigned decimal integer  Γöé Pointer to "unsigned int" Γöé
  2864.   Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  2865.   Γöé "e, f, Γöé Floating-point value con- Γöé Pointer to "float"        Γöé
  2866.   Γöé g"     Γöé sisting of an optional    Γöé                           Γöé
  2867.   Γöé        Γöé sign (+ or -);  a series  Γöé                           Γöé
  2868.   Γöé "E, G" Γöé of one or more decimal    Γöé                           Γöé
  2869.   Γöé        Γöé digits possibly con-      Γöé                           Γöé
  2870.   Γöé        Γöé taining a decimal point;  Γöé                           Γöé
  2871.   Γöé        Γöé and an optional exponent  Γöé                           Γöé
  2872.   Γöé        Γöé (e or E) followed by a    Γöé                           Γöé
  2873.   Γöé        Γöé possibly signed integer   Γöé                           Γöé
  2874.   Γöé        Γöé value                     Γöé                           Γöé
  2875.   Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  2876.   Γöé "c"    Γöé Character;  white-space   Γöé Pointer to "char" large   Γöé
  2877.   Γöé        Γöé characters that are ordi- Γöé enough for input field    Γöé
  2878.   Γöé        Γöé narily skipped are read   Γöé                           Γöé
  2879.   Γöé        Γöé when "c" is specified     Γöé                           Γöé
  2880.   Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  2881.   Γöé "s"    Γöé String                    Γöé Pointer to character      Γöé
  2882.   Γöé        Γöé                           Γöé array large enough for    Γöé
  2883.   Γöé        Γöé                           Γöé input field plus a termi- Γöé
  2884.   Γöé        Γöé                           Γöé nating null character     Γöé
  2885.   Γöé        Γöé                           Γöé ("\0"), which is automat- Γöé
  2886.   Γöé        Γöé                           Γöé ically appended           Γöé
  2887.   Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  2888.   Γöé "n"    Γöé No input read from stream Γöé Pointer to "int", into    Γöé
  2889.   Γöé        Γöé or buffer                 Γöé which is stored the       Γöé
  2890.   Γöé        Γöé                           Γöé number of characters suc- Γöé
  2891.   Γöé        Γöé                           Γöé cessfully read from the   Γöé
  2892.   Γöé        Γöé                           Γöé stream or buffer up to    Γöé
  2893.   Γöé        Γöé                           Γöé that point in the call to Γöé
  2894.   Γöé        Γöé                           Γöé "scanf"                   Γöé
  2895.   Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  2896.   Γöé "p"    Γöé Pointer to "void" con-    Γöé Pointer to "void"         Γöé
  2897.   Γöé        Γöé verted to series of char- Γöé                           Γöé
  2898.   Γöé        Γöé acters                    Γöé                           Γöé
  2899.   Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  2900.   Γöé "lc"   Γöé Multibyte character con-  Γöé Pointer to "wchar_t"      Γöé
  2901.   Γöé        Γöé stant                     Γöé                           Γöé
  2902.   Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  2903.   Γöé "ls"   Γöé Multibyte string constant Γöé Pointer to "wchar_t"      Γöé
  2904.   Γöé        Γöé                           Γöé string                    Γöé
  2905.   ΓööΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ
  2906.  
  2907.  To read strings not delimited by space characters, substitute a set of 
  2908.  characters in brackets ([ ]) for the s (string) type character.  The 
  2909.  corresponding input field is read up to the first character that does not 
  2910.  appear in the bracketed character set.  If the first character in the set is a 
  2911.  caret (^), the effect is reversed:  the input field is read up to the first 
  2912.  character that does appear in the rest of the character set. 
  2913.  
  2914.  To store a string without storing an ending NULL character (\0), use the 
  2915.  specification %ac, where a is a decimal integer.  In this instance, the c type 
  2916.  character means that the argument is a pointer to a character array.  The next 
  2917.  a characters are read from the input stream into the specified location, and 
  2918.  no NULL character is added. 
  2919.  
  2920.  The input for a %x format specifier is interpreted as a hexadecimal number. 
  2921.  
  2922.  
  2923. ΓòÉΓòÉΓòÉ 8.5. SPRINTF -- Formatted print to buffer ΓòÉΓòÉΓòÉ
  2924.  
  2925.  
  2926. Syntax 
  2927.  
  2928. #include <stdio.h>
  2929. #include <wchar.h>
  2930.  
  2931. int sprintf(char *buffer, const char *format-string, ...);
  2932.  
  2933. Description 
  2934.  
  2935. The sprintf function formats and stores a series of characters and values in 
  2936. the array buffer. Any argument-list is converted and put out according to the 
  2937. corresponding format specification in the format-string. 
  2938.  
  2939. The format-string consists of ordinary characters and has the same form and 
  2940. function as the format-string argument for the printf function.  See printf for 
  2941. a description of the format-string and arguments. 
  2942.  
  2943. The sprintf function returns the number of characters written in the array, not 
  2944. counting the ending null character. 
  2945. Related Information 
  2946.  
  2947.    o  fprintf  - Write Formatted Data 
  2948.    o  printf  - Formatted Print 
  2949.    o  sscanf  - Read Data 
  2950.    o  wchar.h 
  2951.  
  2952.  Example 
  2953.  
  2954.   #include <wchar.h>
  2955.  
  2956.   char buffer[200];
  2957.   int i, j;
  2958.   double fp;
  2959.   char *s = "baltimore";
  2960.   char c;
  2961.  
  2962.   int main(void) {
  2963.       c = 'l';
  2964.       i = 35;
  2965.       fp = 1.7320508;
  2966.  
  2967.       /* Format and print various data */
  2968.  
  2969.       j = sprintf(buffer, "%s\n", s);
  2970.       j += sprintf(buffer+j, "%c\n", c);
  2971.       j += sprintf(buffer+j, "%d\n", i);
  2972.       j += sprintf(buffer+j, "%f\n", fp);
  2973.  
  2974.       printf("\nstring:\n%s\ncharacter count = %d\n", buffer, j);
  2975.  
  2976.       }
  2977.  
  2978.  
  2979.   /*********************  Output should be similar to:  *************
  2980.  
  2981.   string:
  2982.   baltimore
  2983.   l
  2984.   35
  2985.   1.732051
  2986.  
  2987.   character count = 24
  2988.  
  2989.   *******************************************************************/
  2990.  
  2991.  This example formats several data values to a buffer and prints out the 
  2992.  results using printf. 
  2993.  
  2994.  
  2995. ΓòÉΓòÉΓòÉ 8.6. SSCANF -- Read data ΓòÉΓòÉΓòÉ
  2996.  
  2997.  
  2998. Syntax 
  2999.  
  3000. #include <wchar.h>
  3001.  
  3002. int sscanf(const char *buffer, const char *format, ...);
  3003.  
  3004. Description 
  3005.  
  3006. The sscanf function reads data from buffer into the locations given by the 
  3007. argument list.  Each argument must be a pointer to a variable with a type that 
  3008. corresponds to a type specifier in the format string. See scanf for a 
  3009. description of the format string. 
  3010.  
  3011. The sscanf function returns the number of fields that were successfully 
  3012. converted and assigned.  The return value does not include fields that were 
  3013. read but not assigned. 
  3014.  
  3015. The return value is WEOF when the end of the string is encountered before 
  3016. anything is converted. 
  3017. Related Information 
  3018.  
  3019.    o  fscanf  - Read Formatted Data 
  3020.    o  scanf  - Read Data 
  3021.    o  sprintf  - Formatted Print to Buffer 
  3022.    o  wchar.h 
  3023.  
  3024.  Example 
  3025.  
  3026.   #include <stdio.h>
  3027.  
  3028.   int main(void) {
  3029.       char    *tokenstring = "15 12 14";
  3030.       wchar_t *widestring = (wchar_t)"ABC Z";
  3031.       wchar_t  ws[81];
  3032.       wchar_t  wc;
  3033.       int   i;
  3034.       float fp;
  3035.       char  s[81];
  3036.       char  c;
  3037.  
  3038.       /* Input various data                              */
  3039.       sscanf(tokenstring, "%s %c%d%f", s, &c, &i, &fp);
  3040.       sscanf(widestring, "%S%C", ws,&wc);
  3041.       /* If there were no space between %s and %c,       */
  3042.       /* sscanf would read the first character following */
  3043.       /* the string, which is a blank space.             */
  3044.  
  3045.       /* Display the data */
  3046.       printf("\nstring = %s\n",s);
  3047.       printf("character = %c\n",c);
  3048.       printf("integer = %d\n",i);
  3049.       printf("floating-point number = %f\n",fp);
  3050.       printf("wide character string = %S\n",ws);
  3051.       printf("wide character = %C\n",wc);
  3052.       }
  3053.  
  3054.  
  3055.   /*****************  Output should be similar to:  *****************
  3056.  
  3057.   string = 15
  3058.   character = 1
  3059.   integer = 2
  3060.   floating-point number = 14.000000
  3061.   wide character string = ABC
  3062.   wide character = Z
  3063.  
  3064.   *******************************************************************/
  3065.  
  3066.  This example uses sscanf to read various data from the string tokenstring, and 
  3067.  then displays the data. 
  3068.  
  3069.  
  3070. ΓòÉΓòÉΓòÉ 9. String Collation Functions ΓòÉΓòÉΓòÉ
  3071.  
  3072.  
  3073. ΓòÉΓòÉΓòÉ 9.1. STRCOLL -- Compares strings ΓòÉΓòÉΓòÉ
  3074.  
  3075.  
  3076. Syntax 
  3077.  
  3078. #include <string.h>
  3079. #include <wchar.h>
  3080.  
  3081. int strcoll(const char *string1, const char *string2);
  3082.  
  3083. Description 
  3084.  
  3085. The strcoll function compares two strings using the collating sequence 
  3086. specified by the program's locale. 
  3087.  
  3088. The strcoll function returns a value indicating the relationship between the 
  3089. strings, as listed below. 
  3090.  
  3091. Value               Meaning
  3092. ________________________________________________________
  3093. Less than 0         string1 less than string2
  3094. 0                   string1 equivalent to string2
  3095. Greater than 0      string1 greater than string2
  3096.  
  3097. Related Information 
  3098.  
  3099.    o  setlocale  - Set Locale 
  3100.    o  wcscmp  - Compare wchar_t Strings 
  3101.    o  wcsncmp  - Compare wchar_t Strings 
  3102.    o  string.h 
  3103.  
  3104.  Example 
  3105.  
  3106.   #include <stdio.h>
  3107.   #include <string.h>
  3108.   #include <wchar.h>
  3109.   #include <locale.h>
  3110.  
  3111.   int main(int argc, char ** argv) {
  3112.       int  result;
  3113.  
  3114.       if ( argc != 3 )
  3115.          printf( "Usage: %s string1 string2\n", argv[0] );
  3116.  
  3117.       else {
  3118.         printf("setlocale set as - %s\n\n",setlocale(LC_ALL,""));
  3119.         result = strcoll( argv[1], argv[2] );
  3120.  
  3121.         if ( result == 0 )
  3122.           printf( "\"%s\" is identical to \"%s\"\n", argv[1], argv[2] );
  3123.         else if ( result < 0 )
  3124.           printf( "\"%s\" is less than \"%s\"\n", argv[1], argv[2] );
  3125.         else
  3126.           printf( "\"%s\" is greater than \"%s\"\n", argv[1], argv[2] );
  3127.         }
  3128.       }
  3129.  
  3130.  
  3131.   /******************  If the input is the strings  ***********************
  3132.   ****************  "firststring" and "secondstring",  ********************
  3133.   *******************  then the expected output is:  **********************
  3134.  
  3135.   "firststring" is less than "secondstring"
  3136.  
  3137.   *************************************************************************/
  3138.  
  3139.  This example compares the two strings passed to main. 
  3140.  
  3141.  
  3142. ΓòÉΓòÉΓòÉ 9.2. STRXFRM -- Transforms strings with reference to Locale ΓòÉΓòÉΓòÉ
  3143.  
  3144.  
  3145. Syntax 
  3146.  
  3147. #include <string.h>
  3148. #include <wchar.h>
  3149.  
  3150. size_t strxfrm(char *string1, const char *string2, size_t count);
  3151.  
  3152. Description 
  3153.  
  3154. The strxfrm function transforms the string pointed to by string2 and places the 
  3155. result into the string pointed to by string1.  The transformation is determined 
  3156. by the program's current locale.  The transformed string is not necessarily 
  3157. readable, but can be used with the strcmp or strncmp functions. 
  3158.  
  3159. The strxfrm function returns the length of the transformed string, excluding 
  3160. the terminating null character.  If the value returned is equal to or greater 
  3161. than count, the contents of the transformed string are indeterminate. 
  3162. Related Information 
  3163.  
  3164.    o  localeconv  - Query Locale Conventions 
  3165.    o  setlocale  - Set Locale 
  3166.    o  strcmp  - Compare Strings 
  3167.    o  strcmpi - Compare Strings 
  3168.    o  strcoll  - Compare Strings 
  3169.    o  stricmp - Compare Strings 
  3170.    o  strncmp  - Compare Strings 
  3171.    o  strnicmp - Compare Strings 
  3172.    o  string.h 
  3173.  
  3174.  Example 
  3175.  
  3176.   #include <stdio.h>
  3177.   #include <string.h>
  3178.  
  3179.   int main(void) {
  3180.       char *string1, buffer[80];
  3181.       int length;
  3182.       char *s1[8];
  3183.       char *s2[8];
  3184.  
  3185.       printf("Type in a string of characters.\n ");
  3186.  
  3187.       string1 = gets(buffer);
  3188.  
  3189.       length = strxfrm(NULL, string1, 0);
  3190.  
  3191.       printf("You would need a %d element array to hold the string\n",length);
  3192.       printf("\n\n%s\n\n transformed according",string1);
  3193.       printf(" to this program's locale. \n");
  3194.  
  3195.       length = strxfrm(s1,"choice",6);
  3196.       length = strxfrm(s2,"crumby",6);
  3197.  
  3198.       if (strcmp(s1,s2) < 0)
  3199.         printf("\nchoice\ncrumby\n");
  3200.       else
  3201.         printf("\ncrumby\nchoice\n");
  3202.       }
  3203.  
  3204.  This example prompts the user to input a string of characters, then uses 
  3205.  strxfrm to transform the string and return its length.  It also shows 
  3206.  collation weights for locale after transformation. 
  3207.  
  3208.  
  3209. ΓòÉΓòÉΓòÉ 9.3. WCSCOLL -- Compares wide-character strings ΓòÉΓòÉΓòÉ
  3210.  
  3211.  
  3212. Syntax 
  3213.  
  3214. #include <wchar.h>
  3215.  
  3216. int wcscoll(const wchar_t *WcString1, const wchar_t *WcString2);
  3217.  
  3218. Description 
  3219.  
  3220. The wcscoll subroutine compares the two wide-character strings pointed to by 
  3221. the WcString1 and WcString2 parameters based on the collation values specified 
  3222. by the LC_COLLATE environment variable of the current locale.  Note: The 
  3223. wcscoll subroutine differs from the wcscmp subroutine in that the wcscoll 
  3224. subroutine compares wide-characters based on their collation values, while the 
  3225. wcscmp subroutine compares wide characters based on their ordinal values.  The 
  3226. wcscoll subroutine is less efficient in terms of time than the wcscmp 
  3227. subroutine because of  the overhead of obtaining the collation values from the 
  3228. current locale.  The wcscoll subroutine may be unsuccessful if the 
  3229. wide-character strings specified by the WcString1 or WcString2 parameter 
  3230. contains characters outside the domain of the current collating  sequence. 
  3231. Parameters  WcString1   Contains a pointer to a wide-character string. 
  3232. WcString2   Contains a pointer to a wide-character string.  Return Values  The 
  3233. wcscoll subroutine returns the following values:  < 0  The collation value of 
  3234. the WcString1 parameter is less than that of the WcString2 parameter.  =0   The 
  3235. collation value of the WcString1 parameter is equal to that of the WcString2 
  3236. parameter.  >0   The collation value of the WcString1 parameter is greater than 
  3237. that of the WcString2 parameter.  The wcscoll subroutine indicates error 
  3238. conditions by setting the errno global variable.  However, there is no return 
  3239. value to indicate an error.  To check for errors, errno should be set to 0, 
  3240. then checked upon return from the wcscoll subroutine.  If errno is nonzero, an 
  3241. error occurred. 
  3242. Related Information 
  3243.  
  3244.    o  wcscmp 
  3245.    o  wchar.h 
  3246.  
  3247.  Example 
  3248.  
  3249.   #include <stdlib.h>
  3250.   #include <stdio.h>
  3251.   #include <wchar.h>
  3252.   #include <locale.h>
  3253.  
  3254.   int main (void) {
  3255.       wchar_t temp1[255], temp2[255];
  3256.       char *s = "crumby";
  3257.       char *t = "choice";
  3258.  
  3259.       printf("\nCalling setlocale\n");
  3260.       printf("Setlocale returns: %s \n", setlocale(LC_ALL, ""));
  3261.  
  3262.       mbstowcs(temp1, s, strlen(s)+1);
  3263.       mbstowcs(temp2, t, strlen(t)+1);
  3264.  
  3265.       if(wcscoll(temp1, temp2) > 0)
  3266.         printf("%S is greater than %S\n",temp1,temp2);
  3267.       else
  3268.         printf("%S is less than %S\n",temp1,temp2);
  3269.  
  3270.       } /* end main */
  3271.  
  3272.  This example sets the current locale and compares two wide-character strings 
  3273.  with respect to the current locale. 
  3274.  
  3275.  
  3276. ΓòÉΓòÉΓòÉ 9.4. WCSXFRM -- Wide char strings to wide char codes of current Locale ΓòÉΓòÉΓòÉ
  3277.  
  3278.  
  3279. Syntax 
  3280.  
  3281. #include <wchar.h>
  3282.  
  3283. size_t wcsxfrm(wchar_t *WcString1, const wchar_t *WcString2, size_t Number);
  3284.  
  3285. Description 
  3286.  
  3287. The wcsxfrm subroutine transforms the wide-character string specified by the 
  3288. WcString2 parameter into a string of wide character codes, based on the 
  3289. collation values of the wide-characters in the current locale as specified by 
  3290. the LC_COLLATE category. No  more  than  the  number  of character codes 
  3291. specified by  the Number parameter are copied into the array specified by the 
  3292. WcString1 parameter.  This transformation is such that when two such 
  3293. transformed wide-character strings  are  obtained  and  the transformed strings 
  3294. are compared using the wcscmp subroutine, the result obtained would  be  the 
  3295. same as that obtained by a direct call to the wcscoll subroutine on the two 
  3296. original wide-character strings. 
  3297. Parameters 
  3298.  
  3299.  WcString1 Contains a pointer to the destination wide-character string. 
  3300.  
  3301.  WcString2 Contains a pointer to the source wide-character string. 
  3302.  
  3303.  Number    Specifies the maximum number of wide-character codes to place into 
  3304.            the array specified by WcString1. 
  3305.  
  3306.  Return Values  If the WcString1 parameter is a NULL pointer, the wcsxfrm 
  3307.  subroutine returns the number of wide-character elements (not including the 
  3308.  wide-character null terminator) required to store the transformed 
  3309.  wide-character string.  If the count specified by the Number parameter is 
  3310.  sufficient to hold the transformed string in the WcString1 parameter, 
  3311.  including the wide-character null terminator, the return value is set to the 
  3312.  actual number of wide-character elements placed in the WcString1 parameter, 
  3313.  not including the wide-character null.  If the return value is equal to or 
  3314.  greater than the value specified by the Number parameter, the contents of the 
  3315.  array pointed to by the WcString1 parameter are indeterminate.  This occurs 
  3316.  whenever the Number parameter value is too small to hold the entire 
  3317.  transformed string.  If the wide-character string pointed to by the WcString2 
  3318.  parameter contains wide-character codes outside  the domain of the collating 
  3319.  sequence defined by the current locale, EINVAL is returned. 
  3320.  Related Information 
  3321.  
  3322.    o  wcscmp 
  3323.    o  wcscoll 
  3324.  
  3325.  Example 
  3326.  
  3327.   #include <stdlib.h>
  3328.   #include <stdio.h>
  3329.   #include <wchar.h>
  3330.   #include <locale.h>
  3331.  
  3332.   int main (void) {
  3333.       char *string1 = "Armadillo aerosol chunks";
  3334.       size_t  length, l1, l2;
  3335.       wchar_t wstring[100];
  3336.       wchar_t ws1[50];
  3337.       wchar_t ws2[50];
  3338.       wchar_t wsa[50];
  3339.       wchar_t wsb[50];
  3340.  
  3341.       mbstowcs(wstring,string1,100);
  3342.  
  3343.       printf("\nLocale now set to --> %s",setlocale(LC_ALL,"Es_ES") );
  3344.       length = wcsxfrm(NULL, wstring, 100);
  3345.       printf("\n%d wide character element array needed to hold the transformed string",length);
  3346.       printf("\n%S\n",wstring);
  3347.  
  3348.       mbstowcs(wsa,"llama",50);
  3349.       mbstowcs(wsb,"lusty",50);
  3350.  
  3351.       l1 = wcsxfrm(ws1,wsa,6);
  3352.       l2 = wcsxfrm(ws2,wsb,6);
  3353.  
  3354.       if (wcscmp(ws1,ws2) < 0)
  3355.         printf("\nlength1-%i-%6S -less than- length2-%i-%6S\n",l1,wsa,l2,wsb);
  3356.       else
  3357.         printf("\nlength2-%i-%6S -less than- length1-%i-%6S\n",l2,wsb,l1,wsa);
  3358.  
  3359.       }
  3360.  
  3361.  This example transforms the wide-character string specified by the "temp2" 
  3362.  parameter into a string of wide-character codes, based on the collation values 
  3363.  of the wide-characters in the current locale as specified by the LC_COLLATE 
  3364.  category. 
  3365.  
  3366.  
  3367. ΓòÉΓòÉΓòÉ 10. Date/Time and Monetary Formatting Functions ΓòÉΓòÉΓòÉ
  3368.  
  3369.  
  3370. ΓòÉΓòÉΓòÉ 10.1. STRFMON -- Formats monetary strings ΓòÉΓòÉΓòÉ
  3371.  
  3372.  
  3373. Syntax 
  3374.  
  3375. #include <monetary.h>
  3376.  
  3377. ssize_t strfmon(char *s, size_t maxsize, const char *format, ...);
  3378.  
  3379. Description 
  3380.  
  3381. The strfmon subroutine converts numeric values to monetary strings according to 
  3382. the specifications in the Format parameter. This parameter also contains 
  3383. numeric values to be converted. Characters are placed into the S array, as 
  3384. controlled by the Format parameter.  The LC_MONETARY category governs the 
  3385. format of the conversion.  The strfmon subroutine can be called multiple times 
  3386. by including additional format structures, as specified by the Format 
  3387. parameter.  The Format parameter specifies a character string that can contain 
  3388. plain characters and conversion specifications.  Plain characters are copied to 
  3389. the output stream.  Conversion specifications result in the fetching of zero or 
  3390. more arguments, which are converted and formatted.  If there are insufficient 
  3391. arguments for the Format parameter, the results are undefined.  If arguments 
  3392. remain after the Format parameter is exhausted, the excess arguments are 
  3393. ignored.  A conversion specification consists of a % (percent) sign, optional 
  3394. flags, optional field width, optional left precision, optional right precision, 
  3395. and a required conversion character that determines the conversion to be 
  3396. performed. 
  3397. Flags One or more of the following optional flags can be specified to control 
  3398. the conversion: 
  3399.  
  3400.  =f        An = (equal sign) followed by a single character that specifies the 
  3401.            numeric fill character.  The default numeric fill character is the 
  3402.            space character.  This flag does not affect field width filling, 
  3403.            which always uses the space character.  This flag is ignored unless 
  3404.            a left precision is specified. 
  3405.  
  3406.  \^        Does not use grouping characters when formatting the currency 
  3407.            amount.  The default is to insert grouping characters if defined for 
  3408.            the current locale. 
  3409.  
  3410.  + or (    Determines the representation of positive and negative currency 
  3411.            amounts.  Only one of these flags may be specified.  The locale's 
  3412.            equivalent of + and - are used if + is specified.  The locale's 
  3413.            equivalent of enclosing negative amounts within parentheses is used 
  3414.            if ( is specified.  If neither flag is included, a default specified 
  3415.            by the current locale is used. 
  3416.  
  3417.  !         Suppresses the currency symbol from the output conversion. 
  3418.  
  3419.  Field Width 
  3420.  
  3421.  w         The decimal-digit string, w, specifies the minimum field width in 
  3422.            which the result of the conversion is right-justified.  If -w is 
  3423.            specified, the result is left-justified. 
  3424.  
  3425.  Left Precision 
  3426.  
  3427.  #n        A # (pound sign) followed by a decimal-digit string, n, specifies 
  3428.            the maximum number of digits to be formatted to the left of the 
  3429.            radix character.  This option can be specified to keep formatted 
  3430.            output from multiple calls to the strfmon subroutine aligned in the 
  3431.            same columns.  It can also be used to fill unused positions with a 
  3432.            special character (for example, $***123.45).  This option causes an 
  3433.            amount to be formatted as if it has the number of digits specified 
  3434.            by the n variable.  If more than n digit positions are required, 
  3435.            this option is ignored.  Digit positions in excess of those required 
  3436.            are filled with the numeric fill character set with the =f flag.  If 
  3437.            defined for the current locale and not suppressed with the \^ flag, 
  3438.            grouping is applied to the fill characters and regular digits. If 
  3439.            the fill character is not 0, however, grouping separators following 
  3440.            a fill character  are replaced by the fill character (for example, 
  3441.            $0,001,234.56 and $****1,234.56). 
  3442.  
  3443.  Right Precision 
  3444.  
  3445.  .p        A .(period) followed by a decimal digit string, p, specifies the 
  3446.            number of digits after  the radix character.  If the value of the p 
  3447.            variable is 0, no radix character is used.  If a right precision is 
  3448.            not specified, a default specified by the current locale is use. 
  3449.            The amount being formatted is rounded to the specified number of 
  3450.            digits prior to formatting. 
  3451.  
  3452.  Conversion Characters 
  3453.  
  3454.  i         The double argument is formatted according to the current locale's 
  3455.            international  currency format; for example, in the U.S.: 1,234.56. 
  3456.  
  3457.  n         The double argument is formatted according to the current locale's 
  3458.            national  currency  format;  for  example,  in  the  U.S.: 
  3459.            $1,234.56. 
  3460.  
  3461.  %         No argument is converted; the conversion specification %% is 
  3462.            replaced by a single %. 
  3463.  
  3464.  Parameters 
  3465.  
  3466.  S         Contains the output of the strfmon subroutine. 
  3467.  
  3468.  MaxSize   Specifies the maximum number of bytes (including the null 
  3469.            terminating byte) that may be placed in the S parameter. 
  3470.  
  3471.  Format    Contains characters and conversion specifications. 
  3472.  
  3473.  Return Values If successful, and if the number of resulting bytes (including 
  3474.  the terminating null character) is not more than the number of bytes specified 
  3475.  by the MaxSize parameter, the strfmon subroutine returns the number of bytes 
  3476.  placed into the array pointed to by the S parameter.  Otherwise, -1 is 
  3477.  returned and the contents of the S array are indeterminate. 
  3478.  Related Information 
  3479.  
  3480.    o  scanf 
  3481.    o  strftime 
  3482.    o  strptime 
  3483.    o  wcsftime 
  3484.    o  monetary.h 
  3485.  
  3486.  Example 
  3487.  
  3488.   #include <stdlib.h>
  3489.   #include <stdio.h>
  3490.   #include <wchar.h>
  3491.   #include <locale.h>
  3492.  
  3493.   int main (void) {
  3494.       char temp1[255], buffer[256];
  3495.       double num = 0.0;
  3496.       size_t rc;
  3497.  
  3498.       printf("Setlocal returns: %s \n", setlocale(LC_ALL, ""));
  3499.  
  3500.       num = 123456.789;
  3501.  
  3502.       rc = strfmon(temp1,sizeof(temp1),"Monetary %n",num);
  3503.  
  3504.       printf("strfmon rc = %ld\n",rc);
  3505.       printf("Monetary value is %.2f    %s\n",num,temp1);
  3506.  
  3507.       } /* end main */
  3508.  
  3509.  This example sets the locale and prints out the monitary information with 
  3510.  respect to that locales specification. 
  3511.  
  3512.  
  3513. ΓòÉΓòÉΓòÉ 10.2. STRFTIME -- Formats time and date ΓòÉΓòÉΓòÉ
  3514.  
  3515.  
  3516. Syntax 
  3517.  
  3518. #include <wchar.h>
  3519.  
  3520. size_t strftime(char *String, size_t Maxsize, const char *Format,
  3521.             const struct tm *TmPtr);
  3522.  
  3523. Description 
  3524.  
  3525. The strftime subroutine converts the internal time and date specification of 
  3526. the tm structure, which is pointed to by the TmPtr parameter, into a character 
  3527. string pointed to by the String parameter under the direction of the format 
  3528. string pointed to by the Format parameter.  The actual values for the format 
  3529. specifiers are dependent on the current settings for the  LC_TIME Category. 
  3530. The tm structure values may be assigned by the user or generated by the 
  3531. localtime or gmtime subroutine.  The resulting string is similar to the result 
  3532. of the printf Format parameter, and is placed in the memory location addressed 
  3533. by the String parameter.  The maximum length of the string is deteremined by 
  3534. the Maxsize parameter and terminates with a null character.  Many conversion 
  3535. specifications are the same as those used by the date command.  The 
  3536. interpretation of some conversion specifications is dependent on the current 
  3537. locale of the process.  The Format parameter is a character string containing 
  3538. two types of objects: plain characters that are simply placed in the output 
  3539. string, and conversion specifications  that  convert  information from the 
  3540. TmPtr parameter into readable form in the output string.   Each conversion 
  3541. specification is a  sequence  of  this form:  %[[-]width][.precision]type  A % 
  3542. (percent sign) introduces a conversion specification.  An optional 
  3543. decimal-digit string specifies a minimum field width.  A converted value that 
  3544. has fewer characters than the field width is padded with spaces to the left. 
  3545. If the decimal digit string is preceded by a - (minus sign), padding with 
  3546. spaces occurs to the right of the converted value.  If no width is given, the 
  3547. appropriate default width is used for numeric  fields, with the field padded to 
  3548. the left with zeros, as required.  For strings, the output  field  is  made 
  3549. exactly wide enough to contain the string.  An optional precision value gives 
  3550. the maximum number of characters to be printed for the conversion 
  3551. specification.  The precision value  is  a decimal-digit string preceded by a 
  3552. period.  If the  value  to be output is longer than the precision, the string 
  3553. is truncated on the right.  The type of conversion is specified by one or two 
  3554. conversion characters.  The characters and their meanings are: 
  3555.  
  3556.  %a        Represents the locale's abbreviated weekday name (for example,Sun). 
  3557.  
  3558.  %A        Represents the locale's full weekday name (for example, Sunday). 
  3559.  
  3560.  %b        Represents the locale's abbreviated month name (for example,Jan). 
  3561.  
  3562.  %B        Represents the locale's full month name (for example, January). 
  3563.  
  3564.  %c        Represents the locale's date and time format. 
  3565.  
  3566.  %C        Represents the century. 
  3567.  
  3568.  %d        Represents the day of the month as a decimal number (01 to 31). 
  3569.  
  3570.  %D        Represents the date in %m/%d/%y format (for example, 01/31/91). 
  3571.  
  3572.  %e        Represents the day of the month as a decimal number ( 1 to 31). An 
  3573.            single digit is preceded by a space character. 
  3574.  
  3575.  %h        Same as %b. 
  3576.  
  3577.  %H        Represents the 24-hour-clock hour as a decimal number (00 to 23). 
  3578.  
  3579.  %I        Represents the 12-hour-clock hour as a decimal number (01 to 12). 
  3580.  
  3581.  %j        Represents the day of the year as a decimal number (001 to 366). 
  3582.  
  3583.  %m        Represents the month of the year as a decimal number (01 to 12). 
  3584.  
  3585.  %M        Represents the minute of the hour as a decimal number (00 to 59). 
  3586.  
  3587.  %n        Specifies a new-line character. 
  3588.  
  3589.  %p        Represents the locale's AM or PM string. 
  3590.  
  3591.  %r        Represents 12-hour clock time with AM/PM notation(%I:%M:%S%p). 
  3592.  
  3593.  %R        Represents 24-hour-clock time in the format %H:%M. 
  3594.  
  3595.  %S        Represents the second of the minute as a decimal number (00 to 61). 
  3596.  
  3597.  %t        Specifies a tab character. 
  3598.  
  3599.  %T        Represents 24-hour-clock time in the format %H:%M:%S. 
  3600.  
  3601.  %u        Represents the day of the week as a decimal number (1 to 7). Monday 
  3602.            is considered as 1. 
  3603.  
  3604.  %U        Represents the week of the year as a decimal number (00 to 53). 
  3605.            Sunday is considered the first day of the week. 
  3606.  
  3607.  % V       Represents the week of the year as a decimal number (01 to 53). 
  3608.            Monday is considered the first day of the week.  If the week 
  3609.            containing 1 January has four or more days in the new year, then it 
  3610.            is considered week 1; otherwise, it is week 53 of the previous year, 
  3611.            and the next week is week 1. 
  3612.  
  3613.  %w        Represents the day of the week as a decimal number (0 to 6). Sunday 
  3614.            is considered as 0. 
  3615.  
  3616.  %W        Represents the week of the year as a decimal number (00 to 53). 
  3617.            Monday is considered the first day of the week. All days in a new 
  3618.            year preceding the first Monday are considered to be week 0. 
  3619.  
  3620.  %x        Represents the locale's date format. 
  3621.  
  3622.  %X        Represents the locale's time format. 
  3623.  
  3624.  %y        Represents the year of the century (00 to 99). 
  3625.  
  3626.  %Y        Represents the year with century as a decimal number (1989). 
  3627.  
  3628.  %Z        Represents the time-zone name if one can be determined (for example, 
  3629.            EST).  No characters are displayed if a time zone cannot be 
  3630.            determined. 
  3631.  
  3632.  %%        Specifies a % (percent) sign. 
  3633.   Parameters 
  3634.  
  3635.    o  String  Pointer to the string to hold the formatted time. 
  3636.  
  3637.    o  Maxsize Maximum length of string pointed to by the String parameter. 
  3638.  
  3639.    o  Format  Pointer to the format character string. 
  3640.  
  3641.    o  TmPtr  Pointer to the time structure that is to be converted. 
  3642.  
  3643.  Return Values  If the total number of resulting bytes, including the 
  3644.  terminating null byte, is not more than the Maxsize value, the strftime 
  3645.  subroutine returns the number of bytes placed into the array pointed to by the 
  3646.  String parameter.  Otherwise, 0 is returned and the contents of the array are 
  3647.  indeterminate. 
  3648.  Related Information 
  3649.  
  3650.    o  strfmon 
  3651.    o  strptime 
  3652.    o  mbstowcs 
  3653.    o  wcsftime 
  3654.    o  localtime 
  3655.    o  gmtime 
  3656.    o  printf 
  3657.  
  3658.  Example 
  3659.  
  3660.   #include <stdlib.h>
  3661.   #include <stdio.h>
  3662.   #include <time.h>
  3663.   #include <wchar.h>
  3664.   #include <locale.h>
  3665.  
  3666.   int main (void) {
  3667.       char temp[255];
  3668.       time_t ltime;
  3669.       size_t rc;
  3670.       struct tm *ptmTemp;
  3671.  
  3672.       printf("\nCalling setlocale\n");
  3673.       printf("Setlocale returns: %s \n", setlocale(LC_ALL, ""));
  3674.  
  3675.       time(<ime);
  3676.  
  3677.       ptmTemp = localtime(<ime);
  3678.  
  3679.       rc = strftime(temp,sizeof(temp),"At   Time %9X   Date %9x %a %A %b %B %h",ptmTemp);
  3680.  
  3681.       printf("strftime rc = %ld\n",rc);
  3682.       printf("%s\n",temp);
  3683.       }
  3684.  
  3685.  This code fragment sets the locale and calls STRFTIME to print out the time 
  3686.  with respect to that locales format. 
  3687.  
  3688.  
  3689. ΓòÉΓòÉΓòÉ 10.3. STRPTIME -- Converts a character string to a time value ΓòÉΓòÉΓòÉ
  3690.  
  3691.  
  3692. Syntax 
  3693.  
  3694. #include <time.h>
  3695.  
  3696. char *strptime(const char *String, const char *Format, struct tm *TmPtr);
  3697.  
  3698. Description 
  3699.  
  3700. The strptime subroutine converts the characters in the String parameter to 
  3701. values that are stored in the TmPtr structure, using the format specified by 
  3702. the Format parameter.  Parameters 
  3703.  
  3704.    o  String   Contains the character string to be converted by the strptime 
  3705.       subroutine. 
  3706.  
  3707.    o  Format  Contains format specifiers for the strptime subroutine. The 
  3708.       Format parameter contains zero or more specifiers.  Each specifier is 
  3709.       composed of one of the following: 
  3710.  
  3711.         -  One or more white-space characters 
  3712.  
  3713.         -  An ordinary character (neither % nor a white-space character) 
  3714.  
  3715.         -  A format specifier. The  LC_TIME category defines the locale values 
  3716.          for the format specifiers.  The following format specifiers are 
  3717.          supported: 
  3718.  
  3719.            %a        Represents the weekday name; abbreviated or full (for 
  3720.                      example, Sun or Sunday) defined for the locale. 
  3721.  
  3722.            %A        Same as %a. 
  3723.  
  3724.            %b        Represents the month name ; abbreviated or full (for 
  3725.                      example, Jan or January) defined for the locale. 
  3726.  
  3727.            %B        Same as %b. 
  3728.  
  3729.            %c        Represents the date and time format defined by the 
  3730.                      locale(%x %X). 
  3731.  
  3732.            %C        Represents the century number (0,99). 
  3733.  
  3734.            %d        Represents the day of the month as a decimal number (1 to 
  3735.                      31). 
  3736.  
  3737.            %D        Represents the date in %m/%d/%y format (for example, 
  3738.                      12/31/93). 
  3739.  
  3740.            %e        Same as %d. 
  3741.  
  3742.            %h        Same as %b. 
  3743.  
  3744.            %H        Represents the 24-hour-clock hour as a decimal number (00 
  3745.                      to 23). 
  3746.  
  3747.            %I        Represents the 12-hour-clock hour as a decimal number (01 
  3748.                      to 12). 
  3749.  
  3750.            %j        Represents the day of the year as a decimal number (001 to 
  3751.                      366). 
  3752.  
  3753.            %m        Represents the month as a decimal number (01 to 12). 
  3754.  
  3755.            %M        Represents the minutes of the hour as a decimal number (00 
  3756.                      to 59). 
  3757.  
  3758.            %n        Specifies any white space. 
  3759.  
  3760.            %p        Represents the AM or PM string defined by the am_pm 
  3761.                      statement. 
  3762.  
  3763.            %r        Represents the time in the format %I:%M:%S%p. 
  3764.  
  3765.            %R        Represents the time in the format %H:%M (for example, 
  3766.                      16:5). 
  3767.  
  3768.            %S        Represents the seconds (00 to 61). 
  3769.  
  3770.            %t        Specifies any white space. 
  3771.  
  3772.            %T        Represents 24-hour-clock time in the format %H:%M:%S. 
  3773.  
  3774.            %U        Represents the week of the year as a decimal number (00 to 
  3775.                      53). Sunday is considered the first day of the week. 
  3776.  
  3777.            %w        Represents the day of the week as a decimal number (0 to 
  3778.                      6). Sunday is considered as 0. 
  3779.  
  3780.            %W        Represents the week of the year as a decimal number (00 to 
  3781.                      53). Monday is considered the first day of the week. 
  3782.  
  3783.            %x        Represents the date, defined by the locale's date format. 
  3784.  
  3785.            %X        Represents the time, defined by the locale's time format. 
  3786.  
  3787.            %y        Represents the year of the century (00 to 99). 
  3788.  
  3789.            %Y        Represents the year including the century (for example, 
  3790.                      1939). 
  3791.  
  3792.            %%        Specifies a % (percent sign) character. A format 
  3793.          specification consisting of white-space characters is performed  by 
  3794.          reading input until the first non-white-space character (which  is 
  3795.          not  read)  or up to no more characters can be read.  A format 
  3796.          specification consisting of an ordinary character is performed by 
  3797.          reading the next character from the String parameter. If  this 
  3798.          character  differs  from  the character comprising  the directive, 
  3799.          the  directive  fails and the differing character and any characters 
  3800.          following  it remain unread.  Case is ignored when matching String 
  3801.          items, such as month or weekday names. 
  3802.  
  3803.    o  TmPtr   Specifies the structure to contain the output of the strptime 
  3804.       subroutine.  If a conversion fails, the contents of the TmPtr structure 
  3805.       are undefined. 
  3806.  
  3807.  Return Values  If successful, the strptime subroutine returns a pointer to the 
  3808.  character following the last character parsed.  Otherwise, a null pointer is 
  3809.  returned. 
  3810.  Related Information 
  3811.  
  3812.    o  scanf 
  3813.    o  strfmon 
  3814.    o  strftime 
  3815.    o  wcsftime 
  3816.  
  3817.  Example 
  3818.  
  3819.   #include <stdlib.h>
  3820.   #include <stdio.h>
  3821.   #include <time.h>
  3822.  
  3823.   #include <wchar.h>
  3824.   #include <locale.h>
  3825.  
  3826.   int main (void) {
  3827.       char temp[255];
  3828.       const char *buf;
  3829.       time_t ltime;
  3830.       char rc;
  3831.       char *rcp;
  3832.       struct tm *ptmTemp;
  3833.  
  3834.       ptmTemp = malloc(sizeof(*ptmTemp));
  3835.  
  3836.       strcpy(temp,"12:34:56 10/21/93");
  3837.  
  3838.       printf("\nCalling setlocale\n");
  3839.       printf("Setlocale returns: %s \n", setlocale(LC_ALL, ""));
  3840.  
  3841.       rcp = strptime(temp, "%T %D", ptmTemp);
  3842.  
  3843.       if(rcp != NULL) {
  3844.         rc = strftime(temp,sizeof(temp),"At   Time %9X   Date %9x %A %B %r",ptmTemp);
  3845.         printf("%s\n",temp);
  3846.         return(1);
  3847.         }
  3848.  
  3849.       return (0);
  3850.       }
  3851.  
  3852.  This example loads the locale and sets the day of the week and the date in the 
  3853.  time structure to 10/21/93 and prints out the results with respect to the 
  3854.  locale loaded. 
  3855.  
  3856.  
  3857. ΓòÉΓòÉΓòÉ 10.4. WCSFTIME -- Converts date and time into a wide character string ΓòÉΓòÉΓòÉ
  3858.  
  3859.  
  3860. Syntax 
  3861.  
  3862. #include <wchar.h>
  3863.  
  3864. size_t wcsftime(wchar_t *WcString, size_t Maxsize, const char *Format,
  3865.             const struct tm *TmPtr);
  3866.  
  3867. Description 
  3868.  
  3869. The wcsftime subroutine formats the data in the TmPtr parameter according to 
  3870. the specification contained in the Format parameter and places the resulting 
  3871. wide character string into the WcString parameter.  Up to Maxsize-1 
  3872. wide-characters are placed into the WcString parameter, terminated by a 
  3873. wide-character NULL.  The wcsftime subroutine behaves as if the character 
  3874. string generated by the strftime subroutine is passed to the mbstowcs 
  3875. subroutine as the character string parameter and the mbstowcs subroutine places 
  3876. the result in the WcString parameter of the wcsftime subroutine, up to the 
  3877. limit of wide character codes specified by the Maxsize parameter  Parameters 
  3878.  
  3879.    o  WcString Contains the output of the wcsftime subroutine. 
  3880.  
  3881.    o  Maxsize  Specifies the maximum number of bytes (including the wide 
  3882.       character  null-terminating  byte) that  may  be  placed  in  the 
  3883.       WcString parameter. 
  3884.  
  3885.    o  Format  Contains format specifiers.  The  LC_TIME category defines the 
  3886.       locale values for the format specifiers.  The Format parameter can use 
  3887.       the same format specifiers as strftime. 
  3888.  
  3889.    o  TmPtr  Contains the data to be converted by the wcsftime subroutine. 
  3890.  
  3891.  Return Values If successful, and if the number of resulting wide-characters 
  3892.  (including  the  wide-character null-terminating byte) is no more than the 
  3893.  number of bytes specified by the Maxsize parameter, the wcsftime subroutine 
  3894.  returns the number of wide-characters (not including the wide-character 
  3895.  null-terminating byte) placed in the WcString parameter.  Otherwise, 0 (zero) 
  3896.  is returned and the contents of the WcString parameter are indeterminate. 
  3897.  Related Information 
  3898.  
  3899.    o  strfmon 
  3900.    o  strftime 
  3901.    o  strptime 
  3902.    o  mbstowcs 
  3903.  
  3904.  Example 
  3905.  
  3906.   #include <stdlib.h>
  3907.   #include <stdio.h>
  3908.   #include <time.h>
  3909.   #include <wchar.h>
  3910.   #include <locale.h>
  3911.  
  3912.   int main (void) {
  3913.       wchar_t temp[255];
  3914.       time_t ltime;
  3915.       size_t rc;
  3916.       struct tm *ptmTemp;
  3917.  
  3918.       printf("\nCalling setlocale\n");
  3919.       printf("Setlocale returns: %s \n", setlocale(LC_ALL, ""));
  3920.  
  3921.       time(<ime);
  3922.       ptmTemp = localtime(<ime);
  3923.  
  3924.       rc=wcsftime(temp,sizeof(temp),"At   Time %9X   Date %9x %a %A %b %B %h",ptmTemp);
  3925.  
  3926.       printf("wcsftime rc = %ld\n",rc);
  3927.       printf("%ls\n",temp);
  3928.       }
  3929.  
  3930.  This example sets the locale and calls WCSFTIME to print out the time in wide 
  3931.  character with respect to that locales format. 
  3932.  
  3933.  
  3934. ΓòÉΓòÉΓòÉ 10.5. WCSTOL -- Converts a wide char string to long int representation ΓòÉΓòÉΓòÉ
  3935.  
  3936.  
  3937. Syntax 
  3938.  
  3939. #include <wchar.h>
  3940.  
  3941. long int wcstol(const wchar_t *nptr, wchar_t **endptr, int base);
  3942.  
  3943. Description 
  3944.  
  3945. The wcstol subroutine converts the initial portion of the wide character string 
  3946. pointed to by the nptr parameter to a signed long integer representation.  The 
  3947. input wide character string is first broken down into three parts:  1.   An 
  3948. initial, possibly empty, sequence of white-space wide character codes (as 
  3949. specified by the iswspace subroutine).  2.   A subject sequence interpreted as 
  3950. an integer and represented in a radix determined by the base parameter.  3.   A 
  3951. final wide character string of one or more unrecognized wide character codes, 
  3952. including the terminating wide character null of the input wide character 
  3953. string.  If possible, the subject is then converted to an integer and the 
  3954. result is returned.  The base parameter can take the following values: 0 
  3955. through 9, or a (or A) through z (or Z).  Potentially, there can be 36 values 
  3956. for the base.   If the base value is 0, the expected form of the subject string 
  3957. is that of an integer constant, optionally preced ed by a plus or minus sign, 
  3958. but not including the integer suffix. If the base value is between 2 and 36, 
  3959. the expected form  of  the subject sequence is a sequence of letters and digits 
  3960. representing an integer in the radix specified by the base parameter, option 
  3961. ally preceded by a plus or minus sign, but not  including  an integer suffix. 
  3962. The letters a (or A) through z (or Z) are ascribed the values of 10 to 35. 
  3963. Only letters whose values are less than that of the base are permitted.  If 
  3964. the value of base is 16, the characters  0x  or  0X  may  optionally  precede 
  3965. the sequence of letters or digits, following the sign, if present.  The wide 
  3966. character string is parsed to skip the initial space characters (as determined 
  3967. by the iswspace subroutine).  Any non space character signifies  the start of a 
  3968. subject string that may form an integer in the radix specified by the base 
  3969. parameter. The  subject  sequence is defined to be the longest initial 
  3970. substring that  is a long integer of the expected form.  Any character not 
  3971. satisfying this form begins the final portion of the wide character string 
  3972. pointed to by the endptr parameter on return from the call to the wcstol 
  3973. subroutine. 
  3974. Parameters  nptr  Contains a pointer to the wide character string to be 
  3975. converted to a double-precision number.  endptr  Contains a pointer to the 
  3976. position in the nptr string where a wide character is found that is not a valid 
  3977. character for the purpose of this conversion.  base  Specifies the radix in 
  3978. which the characters are interpreted. 
  3979. Return Values  The wcstol subroutine returns the converted value of long 
  3980. integer if  the  expected form is found.  If no conversion could be  performed, 
  3981. a value of 0 is returned.  If the converted value is out side the range of 
  3982. representable values, LONG_MAX or LONG_MIN is returned (according to the sign 
  3983. of the value),  and  the value of the errno global variable is set to ERANGE. 
  3984. If the base value specified by the base parameter is not supported, EINVAL is 
  3985. returned.  If the subject sequence has the expected form, it is interpreted as 
  3986. an integer constant in the appropriate base.  A pointer to the final string is 
  3987. stored in the endptr parameter if that parameter is not a null pointer.  If the 
  3988. subject sequence is  empty or does not have a valid form, no conversion  is 
  3989. done.  The value of the nptr parameter is stored in the endptr parameter if 
  3990. that parameter is not a null pointer.  Since 0, LONG_MIN, and LONG_MAX are 
  3991. returned in the event of an error and are also valid returns if the wcstol 
  3992. subroutine is successful, applications should set the errno global variable to 
  3993. 0 before calling the wcstol subroutine, and then check the errno global 
  3994. variable after return.  Then, if the errno global variable has changed, an 
  3995. error occurred. 
  3996. Related Information 
  3997.  
  3998.    o  iswspace - Checks for a valid wide character space. 
  3999.    o  wcstod  - Converts a wide character string to a double-precision number. 
  4000.    o  wsctoul  - Converts wide character strings to unsigned long integer. 
  4001.    o  wchar.h  - Header file for wide character function prototypes. 
  4002.  
  4003.  Example 
  4004.  
  4005.   #include <stdio.h>
  4006.   #include <wchar.h>
  4007.  
  4008.   #define SIZE  40
  4009.  
  4010.   main()
  4011.   {
  4012.  
  4013.     wchar_t WCString[SIZE],
  4014.             *endptr;
  4015.  
  4016.     long int retval;
  4017.  
  4018.     /** Set errno to 0 so a failure for wcstol can be **detected */
  4019.     errno=0;
  4020.  
  4021.     mbstowcs(WCString,"-100000",SIZE);
  4022.  
  4023.     /*
  4024.      **Let WCString point to a wide character null terminated
  4025.      ** string containing a signed long integer value
  4026.      **
  4027.     */
  4028.  
  4029.     retval = wcstol ( WCString, &endptr, 10 );
  4030.     /* Check errno, if it is non-zero, wcstol failed */
  4031.     if (errno != 0)
  4032.     {
  4033.       /*Error handling*/
  4034.       printf("An error occurred during conversion\n");
  4035.     }
  4036.     else if (retval == 0)
  4037.     {
  4038.       /* No conversion could be performed */
  4039.       /* Handle this case accordingly. */
  4040.       printf("No conversion could be performed\n");
  4041.     }
  4042.     /* retval contains long integer */
  4043.     printf("This should be a long integer %ld\n",retval);
  4044.   }
  4045.  
  4046.  The following converts a wide character string to a signed long integer. 
  4047.  
  4048.  
  4049. ΓòÉΓòÉΓòÉ 10.6. WCSTOUL -- Converts wide char strings to unsigned long int ΓòÉΓòÉΓòÉ
  4050.  
  4051.  
  4052. Syntax 
  4053.  
  4054. #include <wchar.h>
  4055.  
  4056. unsigned long wcstoul(const wchar_t *nptr,
  4057.                   wchar_t **endptr, int base);
  4058.  
  4059. Description 
  4060.  
  4061. The wcstoul subroutine converts the initial portion of the wide character 
  4062. string pointed to by the nptr parameter to an unsigned long integer 
  4063. representation.  To  do  this, it parses the wide character string pointed to 
  4064. by the nptr parameter to obtain a valid string (that is, subject string) for 
  4065. the purpose of conversion to an unsigned long integer.  It then points the 
  4066. endptr parameter to the position where an unrecognized character, including the 
  4067. terminating null, is found.  The base specified by the base parameter can take 
  4068. the following values:  0  through 9, a (or A) through z (or Z). Potentially, 
  4069. there can be 36 values for the base.  If the base value is 0, the expected form 
  4070. of the subject string is that  of  an  unsigned integer constant, with an 
  4071. optional + (plus) or - (minus)  sign, but not including the integer suffix. If 
  4072. the base value is between 2 and 36, the expected form of the subject sequence 
  4073. is  a sequence of letters and digits representing an integer with the  radix 
  4074. specified by the base parameter, optionally preceded by a + or - sign, but not 
  4075. including an integer suffix.  The letters a (or A) through z (or Z) are 
  4076. ascribed the values of 10 to  35.   Only letters whose values are less than 
  4077. that of the base are permitted.  If the value  of  base is 16, the characters 
  4078. 0x or 0X may optionally precede the sequence of letters or digits, following 
  4079. the sign, if present.  The wide character string is parsed to skip the initial 
  4080. white space characters (as determined by the iswspace subroutine).  Any 
  4081. non-space character signifies the  start of a subject string that may form an 
  4082. unsigned long integer in the radix specified by the base parameter.  The 
  4083. subject sequence is defined to be the longest initial substring that is an 
  4084. unsigned long integer of the expected form.  Any character not satisfying this 
  4085. expected form begins the final portion of the wide character string pointed to 
  4086. by the endptr parameter on return from the call to this subroutine. 
  4087. Parameters  nptr Contains a pointer to the wide character string to be 
  4088. converted to an unsigned long integer.  endptr Contains a pointer to the 
  4089. position in the nptr string where a wide character is found that is not a valid 
  4090. character for the purpose of this conversion.  base Specifies the radix in 
  4091. which the wide characters are interpreted. 
  4092. Return Values  The wcstoul subroutine returns the converted value of the 
  4093. unsigned integer if the expected  form  is found.  If no conversion could be 
  4094. performed, a value of 0 is  returned.  If the converted value is outside the 
  4095. range of representable values, ULONG_MAX is returned, and the value of the 
  4096. errno global variable is set to ERANGE.  If the subject sequence has the 
  4097. expected form, it is interpreted as an integer constant in the appropriate 
  4098. base.  A pointer to the final string is stored in the endptr parameter if that 
  4099. parameter is not a null pointer.  If the subject sequence is empty or does not 
  4100. have a valid form, no conversion is done and the value of the nptr parameter is 
  4101. stored in the endptr parameter if it is not a null pointer.  If the radix 
  4102. specified by the base parameter is not supported, EINVAL is returned.  If the 
  4103. value to be returned is not representable, ERANGE is returned. 
  4104. Related Information 
  4105.  
  4106.    o  iswspace - Checks for a valid wide character space. 
  4107.    o  wcstod  - Converts a wide character string to a double-precision number. 
  4108.    o  wsctoul  - Converts wide character strings to unsigned long integer. 
  4109.    o  wchar.h  - Header file for wide character function prototypes. 
  4110.  
  4111.  Example 
  4112.  
  4113.   #include <stdio.h>
  4114.   #include <wchar.h>
  4115.  
  4116.   #define SIZE  40
  4117.  
  4118.   main()
  4119.   {
  4120.  
  4121.     wchar_t WCString[SIZE],
  4122.             *endptr;
  4123.  
  4124.     unsigned long int retval;
  4125.  
  4126.     /** Set errno to 0 so a failure for wcstol can be **detected */
  4127.     errno=0;
  4128.  
  4129.     mbstowcs(WCString,"100000",SIZE);
  4130.  
  4131.     /*
  4132.      **Let WCString point to a wide character null terminated
  4133.      ** string containing a signed unsigned long integer value
  4134.      **
  4135.     */
  4136.  
  4137.     retval = wcstol ( WCString, &endptr, 10 );
  4138.     /* Check errno, if it is non-zero, wcstol failed */
  4139.     if (errno != 0)
  4140.     {
  4141.       /*Error handling*/
  4142.       printf("An error occurred during conversion\n");
  4143.     }
  4144.     else if (retval == ULONG_MAX)
  4145.     {
  4146.       /* No conversion could be performed */
  4147.       /* Handle this case accordingly. */
  4148.       printf("No conversion could be performed\n");
  4149.     }
  4150.     /* retval contains long integer */
  4151.     printf("This should be a unsigned long integer %ld\n",retval);
  4152.   }
  4153.  
  4154.  This example converts a wide character string to an unsigned long integer. 
  4155.  
  4156.  
  4157. ΓòÉΓòÉΓòÉ 11. WideChar String Functions ΓòÉΓòÉΓòÉ
  4158.  
  4159.  
  4160. ΓòÉΓòÉΓòÉ 11.1. WCSCAT -- Appends string1 to string2 ΓòÉΓòÉΓòÉ
  4161.  
  4162.  
  4163. Syntax 
  4164.  
  4165. #include <wchar.h>
  4166. wchar_t *wcscat(wchar_t *string1, const wchar_t *string2);
  4167.  
  4168. Description. 
  4169.  
  4170. The wcscat function appends a copy of the string pointed to by string2 to the 
  4171. end of the string pointed to by string1. 
  4172.  
  4173. The wcscat function operates on null-terminated wchar_t strings. The string 
  4174. arguments to this function should contain a wchar_t null character marking the 
  4175. end of the string. Boundary checking is not performed. 
  4176.  
  4177. The wcscat function returns the value of string1. 
  4178. Related Information 
  4179.  
  4180.    o  strcat  - Concatenate Strings 
  4181.    o  strncat  - Concatenate Strings 
  4182.    o  wcsncat  - Concatenate wchar_t Strings 
  4183.    o  wchar.h 
  4184.  
  4185.  Example 
  4186.  
  4187.   #include <stdio.h>
  4188.   #include <wchar.h>
  4189.  
  4190.   int main(void) {
  4191.       wchar_t buffer1[40];
  4192.       wchar_t string[40];
  4193.       wchar_t * ptr;
  4194.  
  4195.       mbstowcs(buffer1,"computer",9);
  4196.       mbstowcs(string," program",9);
  4197.  
  4198.       ptr = wcscat( buffer1, string );
  4199.  
  4200.       printf( "buffer1 = %S\n", buffer1 );
  4201.       }
  4202.   /****************  Output should be similar to:  ******************
  4203.  
  4204.   buffer1 = computer program
  4205.  
  4206.   *******************************************************************/
  4207.  
  4208.  This example creates the wide character string "computer program" using 
  4209.  wcscat. 
  4210.  
  4211.  
  4212. ΓòÉΓòÉΓòÉ 11.2. WCSCHR -- Searches string1 for a wide character ΓòÉΓòÉΓòÉ
  4213.  
  4214.  
  4215. Syntax 
  4216.  
  4217. #include <wchar.h>
  4218.  
  4219. wchar_t  *wcschr(const wchar_t *ws, wint_t wc);
  4220.  
  4221. Description. 
  4222.  
  4223. The wcschr function searches ws for the occurrence of wc. wc may be a wint_t 
  4224. null character (L0); the wchar_t null character at the end of ws is included in 
  4225. the search. 
  4226.  
  4227. The wcschr function operates on null-terminated wchar_t strings. The ws 
  4228. argument to this function should contain a wchar_t null character marking the 
  4229. end of the string. 
  4230.  
  4231. The wcschr function returns a pointer to the first occurrence of character in 
  4232. ws. If the character is not found, a NULL pointer is returned. 
  4233. Related Information 
  4234.  
  4235.    o  wcscspn  - Find Offset of First wchar_t Match 
  4236.    o  wcspbrk  - Locate wchar_t Characters in wchar_t String 
  4237.    o  wcsrchr  - Locate wchar_t Character in wchar_t String 
  4238.    o  wcsspn  - Search wchar_t Characters in wchar_t String 
  4239.    o  wcswcs  - Locate wchar_t Substring in wchar_t String 
  4240.    o  wchar.h 
  4241.  
  4242.  Example 
  4243.  
  4244.   #include <stdio.h>
  4245.   #include <wchar.h>
  4246.  
  4247.   int main(void) {
  4248.       wchar_t buffer1[20];
  4249.       wchar_t * ptr;
  4250.       wchar_t wc = (wchar_t)'p';
  4251.  
  4252.       mbstowcs(buffer1,"computer program",17);
  4253.  
  4254.       ptr = wcschr( buffer1, wc );
  4255.  
  4256.       printf( "The first occurrence of %C in '%S' is '%S'\n",
  4257.                          wc, buffer1, ptr );
  4258.  
  4259.       }
  4260.   /****************  Output should be similar to:  ******************
  4261.  
  4262.   The first occurrence of p in 'computer program' is 'puter program'
  4263.  
  4264.   *******************************************************************/
  4265.  
  4266.  This example finds the first occurrence of the character p in the wide 
  4267.  character string "computer program". 
  4268.  
  4269.  
  4270. ΓòÉΓòÉΓòÉ 11.3. WCSCMP -- Compares string1 to string2 ΓòÉΓòÉΓòÉ
  4271.  
  4272.  
  4273. Syntax 
  4274.  
  4275. #include <wchar.h>
  4276.  
  4277. int wcscmp(const wchar_t *ws1, const wchar_t *ws2);
  4278.  
  4279. Description. 
  4280.  
  4281. The wcscmp function compares two wchar_t strings. 
  4282.  
  4283. The wcscmp function operates on null-terminated wchar_t strings. The string 
  4284. arguments to this function should contain a wchar_t null character marking the 
  4285. end of the string. Boundary checking is not performed when a string is added to 
  4286. or copied. 
  4287.  
  4288. The wcscmp function returns a value indicating the relationship between the two 
  4289. strings, as follows: 
  4290.  
  4291. Value               Meaning
  4292. Less than 0         ws1 less than ws2
  4293. 0                   ws1 identical to ws2
  4294. Greater than 0      ws1 greater than ws2.
  4295.  
  4296. Related Information 
  4297.  
  4298.    o  wcsncmp  - Compare wchar_t Strings 
  4299.    o  wchar.h 
  4300.  
  4301.  Example 
  4302.  
  4303.   #include <stdio.h>
  4304.   #include <wchar.h>
  4305.  
  4306.   int main(void) {
  4307.       int  result;
  4308.       wchar_t ws1[20];
  4309.       wchar_t ws2[20];
  4310.  
  4311.       mbstowcs(ws1,"abcdef",7);
  4312.       mbstowcs(ws2,"abcdefg",8);
  4313.  
  4314.       result=wcscmp( ws1, ws2 );
  4315.  
  4316.       if ( result == 0 )
  4317.         printf( "\"%S\" is identical to \"%S\"\n", ws1, ws2);
  4318.       else if ( result < 0 )
  4319.         printf( "\"%S\" is less than \"%S\"\n", ws1, ws2 );
  4320.       else
  4321.         printf( "\"%S\" is greater than \"%S\"\n", ws1, ws2);
  4322.       }
  4323.   /****************  Output should be similar to:  ******************
  4324.  
  4325.   "abcdef" is less than "abcdefg"
  4326.  
  4327.   *******************************************************************/
  4328.  
  4329.  This example compares the wide character string ws1 to ws2 using wcscmp. 
  4330.  
  4331.  
  4332. ΓòÉΓòÉΓòÉ 11.4. WCSCPY -- Copies string2 into string1 ΓòÉΓòÉΓòÉ
  4333.  
  4334.  
  4335. Syntax 
  4336.  
  4337. #include <wchar.h>
  4338.  
  4339. wchar_t *wcscpy(wchar_t *ws1, const wchar_t *ws2);
  4340.  
  4341. Description. 
  4342.  
  4343. The wcscpy function copies the contents of ws2 (including the ending wchar_t 
  4344. null character) into ws1. 
  4345.  
  4346. The wcscpy function operates on null-terminated wchar_t strings. The string 
  4347. arguments to this function should contain a wchar_t null character marking the 
  4348. end of the string. Boundary checking is not performed. 
  4349.  
  4350. The wcscpy function returns the value of ws1. 
  4351. Related Information 
  4352.  
  4353.    o  wcsncpy  - Copy wchar_t Strings 
  4354.    o  wchar.h 
  4355.  
  4356.  Example 
  4357.  
  4358.   #include <stdio.h>
  4359.   #include <wchar.h>
  4360.  
  4361.   int main(void) {
  4362.       wchar_t source[ 80 ];
  4363.       wchar_t target[ 80 ];
  4364.       wchar_t *wsptr;
  4365.  
  4366.       mbstowcs(ws1,"This is the source string",40);
  4367.       mbstowcs(ws1,"And this is the target string",40);
  4368.  
  4369.       printf( "Target is originally = \"%S\"\n", target );
  4370.  
  4371.       wsptr = wcscpy( target, source );
  4372.  
  4373.       printf( "After wcscpy, target becomes \"%S\"\n", wsptr );
  4374.       }
  4375.   /****************  Output should be similar to:  ******************
  4376.  
  4377.   Target is originally = "And this is the target string"
  4378.   After wcscpy, target becomes "This is the source string"
  4379.  
  4380.   *******************************************************************/
  4381.  
  4382.  This example copies the contents of source string to a destination string. 
  4383.  
  4384.  
  4385. ΓòÉΓòÉΓòÉ 11.5. WCSCSPN -- Finds length of complementary wide char substring ΓòÉΓòÉΓòÉ
  4386.  
  4387.  
  4388. Syntax 
  4389.  
  4390. #include <wchar.h> /* SAA extension to ANSI */
  4391.  
  4392. size_t wcscspn(const wchar_t *ws1, const wchar_t *ws2);
  4393.  
  4394. Description. 
  4395.  
  4396. The wcscspn function determines the number of wchar_t characters in the initial 
  4397. segment of the string pointed to by ws1 that do not appear in the string 
  4398. pointed to by ws2. 
  4399.  
  4400. The wcscspn function operates on null-terminated wchar_t strings. The string 
  4401. arguments to these functions should contain a wchar_t null character marking 
  4402. the end of the string. 
  4403.  
  4404. The wcscspn function returns the number of wchar_t characters in the segment. 
  4405. Related Information 
  4406.  
  4407.    o  wcsspn  - Search wchar_t Characters in String 
  4408.    o  wcswcs  - Locate wchar_t Substring in wchar_t String 
  4409.    o  wchar.h 
  4410.  
  4411.  Example 
  4412.  
  4413.   #include <stdio.h>
  4414.   #include <wchar.h>
  4415.  
  4416.   int main(void) {
  4417.       wchar_t ws[ 80 ];
  4418.       wchar_t * substring[ 10 ];
  4419.  
  4420.       mbstowcs(ws,"This is the source string",40);
  4421.       mbstowcs(substring,"axle",10);
  4422.  
  4423.       printf( "The first %i characters in the string \"%S\" are not "
  4424.          "in the string \"%S\" \n", wcscspn( ws, substring),
  4425.          ws, substring );
  4426.  
  4427.       }
  4428.  
  4429.  
  4430.   /****************  Output should be similar to:  ************************
  4431.  
  4432.   The first 10 characters in the string "This is the source string" are not
  4433.   in the string "axle"
  4434.  
  4435.   *************************************************************************/
  4436.  
  4437.  This example uses wcscspn to find the first occurrence of any of the 
  4438.  characters a, x, l, or e in ws. 
  4439.  
  4440.  
  4441. ΓòÉΓòÉΓòÉ 11.6. WCSLEN -- Finds length of wide character string ΓòÉΓòÉΓòÉ
  4442.  
  4443.  
  4444. Syntax 
  4445.  
  4446. #include <wchar.h>
  4447.  
  4448. size_t wcslen(const wchar_t *ws);
  4449.  
  4450. Description. 
  4451.  
  4452. The wcslen function computes the number of wchar_t characters in the string 
  4453. pointed to by ws. 
  4454.  
  4455. The wcslen function returns the number of wchar_t characters that precede the 
  4456. terminating wchar_t null character. 
  4457. Related Information 
  4458.  
  4459.    o  mblen  - Multibyte String Length 
  4460.    o  strlen  - Determine String Length 
  4461.    o  wchar.h 
  4462.  
  4463.  Example 
  4464.  
  4465.   #include <stdio.h>
  4466.   #include <wchar.h>
  4467.  
  4468.   int main(void) {
  4469.       wchar_t  ws[ 20 ];
  4470.  
  4471.       mbstowcs(ws,"abcdef",7);
  4472.       printf( "Length of \"%S\" is %i\n", ws, wcslen( ws ));
  4473.  
  4474.       }
  4475.   /****************  Output should be similar to:  ******************
  4476.  
  4477.   Length of "abcdef" is 6
  4478.  
  4479.   *******************************************************************/
  4480.  
  4481.  This example computes the length of a wchar_t string. 
  4482.  
  4483.  
  4484. ΓòÉΓòÉΓòÉ 11.7. WCSNCAT -- Appends wide characters from string2 to string1 ΓòÉΓòÉΓòÉ
  4485.  
  4486.  
  4487. Syntax 
  4488.  
  4489. #include <wchar.h>
  4490.  
  4491. wchar_t *wcsncat(wchar_t *ws1, const wchar_t *ws2, size_t count);
  4492.  
  4493. Description. 
  4494.  
  4495. The wcsncat function appends up to count wide characters from ws2 to the end of 
  4496. ws1 and appends a wchar_t null character to the result. 
  4497.  
  4498. The wcsncat function operates on null-terminated wchar_t strings. The string 
  4499. arguments to this function should contain a wchar_t null character marking the 
  4500. end of the string. 
  4501.  
  4502. The wcsncat function returns ws1. 
  4503. Related Information 
  4504.  
  4505.    o  strncat  - Concatenate Strings 
  4506.    o  strcat  - Concatenate Strings 
  4507.    o  wcscat  - Append wchar_t Strings 
  4508.    o  wchar.h 
  4509.  
  4510.  Example 
  4511.  
  4512.   #include <stdio.h>
  4513.   #include <wchar.h>
  4514.  
  4515.   int main(void) {
  4516.       wchar_t * buffer1;
  4517.       wchar_t * buffer2;
  4518.       wchar_t * ptr;
  4519.  
  4520.       buffer1 = (wchar_t *)malloc(80);
  4521.       buffer2 = (wchar_t *)malloc(20);
  4522.  
  4523.       mbstowcs(buffer1,"computer",9);
  4524.       mbstowcs(buffer2," program",9);
  4525.  
  4526.       /* Call wcscat with buffer1 and " program" */
  4527.  
  4528.       ptr = wcscat( buffer1, buffer2 );
  4529.       printf( "wcscat : buffer1 = \"%S\"\n", buffer1 );
  4530.  
  4531.       /* Reset buffer1 to contain just the string "computer" again */
  4532.  
  4533.       memset( buffer1, '\0', sizeof( buffer1 ));
  4534.       mbstowcs(buffer1,"computer",9);
  4535.  
  4536.       /* Call wcsncat with buffer1 and " program" */
  4537.       ptr = wcsncat( buffer1, buffer2, 3 );
  4538.  
  4539.       printf( "wcsncat: buffer1 = \"%S\"\n", buffer1 );
  4540.       }
  4541.   /****************  Output should be similar to:  ******************
  4542.  
  4543.   wcscat : buffer1 = "computer program"
  4544.   wcsncat: buffer1 = "computer pr"
  4545.  
  4546.   *******************************************************************/
  4547.  
  4548.  This example demonstrates the difference between wcscat and wcsncat. Wcscat 
  4549.  appends the entire second string to the first whereas wcsncat appends only the 
  4550.  specified number of characters in the second string to the first. 
  4551.  
  4552.  
  4553. ΓòÉΓòÉΓòÉ 11.8. WCSNCMP -- Compares subset string2 to string1 ΓòÉΓòÉΓòÉ
  4554.  
  4555.  
  4556. Syntax 
  4557.  
  4558. #include <wchar.h>
  4559.  
  4560. int wcsncmp(const wchar_t *ws1, const wchar_t *ws2, size_t count);
  4561.  
  4562. Description. 
  4563.  
  4564. The wcsncmp function compares up to count wide characters in ws1 to ws2. 
  4565.  
  4566. The wcsncmp function operates on null-terminated wchar_t strings. The string 
  4567. arguments to this function should contain a wchar_t null character marking the 
  4568. end of the string. 
  4569.  
  4570. The wcsncmp function returns a value indicating the relationship between the 
  4571. two strings, as follows: 
  4572.  
  4573. Value               Meaning
  4574. Less than 0         ws1 less than ws2
  4575. 0                   ws1 identical to ws2
  4576. Greater than 0      ws1 greater than ws2.
  4577.  
  4578. Related Information 
  4579.  
  4580.    o  wcscmp  - Compare wchar_t Strings 
  4581.    o  strcoll  - Compare wchar_t Strings 
  4582.    o  wchar.h 
  4583.  
  4584.  Example 
  4585.  
  4586.   #include <stdio.h>
  4587.   #include <wchar.h>
  4588.  
  4589.   int main(void) {
  4590.       int  result;
  4591.       wchar_t buffer1[20];
  4592.       wchar_t buffer2[20];
  4593.  
  4594.       mbstowcs(buffer1,"abcdefg",8);
  4595.       mbstowcs(buffer2,"abcfg",6);
  4596.  
  4597.       result = wcscmp( buffer1, buffer2 );
  4598.  
  4599.       printf( "Comparison of each character\n" );
  4600.       printf( "  wcscmp: " );
  4601.  
  4602.       if ( result == 0 )
  4603.         printf( "\"%S\" is identical to \"%S\"\n", buffer1, buffer2);
  4604.       else if ( result < 0 )
  4605.         printf( "\"%S\" is less than \"%S\"\n", buffer1, buffer2 );
  4606.       else
  4607.         printf( "\"%S\" is greater than \"%S\"\n", buffer1, buffer2 );
  4608.  
  4609.       result = wcsncmp( buffer1, buffer2, 3);
  4610.  
  4611.       printf( "\nComparison of only the first 3 characters\n" );
  4612.       printf( "  wcsncmp: " );
  4613.  
  4614.       if ( result == 0 )
  4615.         printf( "\"%S\" is identical to \"%S\"\n", buffer1, buffer2);
  4616.       else if ( result < 0 )
  4617.         printf( "\"%S\" is less than \"%S\"\n", buffer1, buffer2 );
  4618.       else
  4619.         printf( "\"%S\" is greater than \"%S\"\n", buffer1, buffer2 );
  4620.  
  4621.       }
  4622.   /****************  Output should be similar to:  ******************
  4623.  
  4624.   Comparison of each character
  4625.   wcscmp: "abcdefg" is less than "abcfg"
  4626.  
  4627.   Comparison of only the first 3 characters
  4628.   wcsncmp: "abcdefg" is identical to "abcfg"
  4629.  
  4630.   *******************************************************************/
  4631.  
  4632.  This example demonstrates the difference between wcscmp and wcsncmp. 
  4633.  
  4634.  
  4635. ΓòÉΓòÉΓòÉ 11.9. WCSNCPY -- Copies n wide characters from string2 to string1 ΓòÉΓòÉΓòÉ
  4636.  
  4637.  
  4638. Syntax 
  4639.  
  4640. #include <wchar.h>
  4641.  
  4642. wchar_t *wcsncpy(wchar_t *ws1, const wchar_t *ws2, size_t count);
  4643.  
  4644. Description. 
  4645.  
  4646. The wcsncpy function copies up to count wide characters from ws2 to ws1. If ws2 
  4647. is shorter than count characters, string1 is padded out to count characters 
  4648. with wchar_t null characters. 
  4649.  
  4650. The wcsncpy function operates on null-terminated wchar_t strings. The string 
  4651. arguments to this function should contain a wchar_t null character marking the 
  4652. end of the string. 
  4653.  
  4654. The wcsncpy function returns ws1. 
  4655. Related Information 
  4656.  
  4657.    o  wcscpy  - Copy wchar_t Strings 
  4658.    o  wchar.h 
  4659.  
  4660.  Example 
  4661.  
  4662.   #include <stdio.h>
  4663.   #include <wchar.h>
  4664.  
  4665.   int main(void) {
  4666.       wchar_t source[ 20 ];
  4667.       wchar_t source1[ 20 ];
  4668.       wchar_t target[ 20 ];
  4669.       wchar_t target1[ 20 ];
  4670.       wchar_t * return_string;
  4671.       int    index = 5;
  4672.  
  4673.       mbstowcs(source,"123456789",10);
  4674.       mbstowcs(source1,"123456789",10);
  4675.       mbstowcs(target,"abcdefg",8);
  4676.       mbstowcs(target1,"abcdefg",8);
  4677.  
  4678.       printf( "target is originally = '%S'\n", target );
  4679.  
  4680.       return_string = wcscpy( target, source );
  4681.  
  4682.       printf( "After wcscpy, target becomes '%S'\n\n", target );
  4683.  
  4684.       printf( "target is originally = '%S'\n", target1 );
  4685.  
  4686.       return_string = wcsncpy( target1, source1, index );
  4687.  
  4688.       printf( "After wcsncpy 'n=5', target becomes '%S'\n", target1 );
  4689.  
  4690.       }
  4691.   /****************  Output should be similar to:  ******************
  4692.  
  4693.   target is originally = 'abcdefg'
  4694.   After wcscpy 'n=5', target becomes '123456789'
  4695.  
  4696.   target1 is originally = 'abcdefg'
  4697.   After wcsncpy, target1 becomes '12345fg'
  4698.  
  4699.   *******************************************************************/
  4700.  
  4701.  This example demonstrates the difference between wcscpy and wcsncpy. 
  4702.  
  4703.  
  4704. ΓòÉΓòÉΓòÉ 11.10. WCSPBRK -- Locates occurrence of wide characters from string2 in string1 ΓòÉΓòÉΓòÉ
  4705.  
  4706.  
  4707. Syntax 
  4708.  
  4709. #include <wchar.h>
  4710.  
  4711. wchar_t *wcspbrk(const wchar_t *ws1, const wchar_t *ws2);
  4712.  
  4713.  
  4714. Description. 
  4715.  
  4716. The wcspbrk function locates the first occurrence in the string pointed to by 
  4717. ws1 of any character from the string pointed to by ws2. 
  4718.  
  4719. The wcspbrk function returns a pointer to the character, or NULL if no wchar_t 
  4720. from ws2 occurs in ws1. 
  4721. Related Information 
  4722.  
  4723.    o  wcschr  - Search wchar_t String for Given wchar_t 
  4724.    o  wcscspn  - Find Offset of First wchar_t Match 
  4725.    o  wcsncmp  - Compare wchar_t Strings 
  4726.    o  wcsrchr  - Locate wchar_t Character in String 
  4727.    o  wcsspn  - Search wchar_t Characters in String 
  4728.    o  wcswcs  - Locate wchar_t Substring in wchar_t String 
  4729.    o  wchar.h 
  4730.  
  4731.  Example 
  4732.  
  4733.   #include <stdio.h>
  4734.   #include <wchar.h>
  4735.  
  4736.   int main(void) {
  4737.       wchar_t  *result;
  4738.       wchar_t  ws[ 30 ];
  4739.       wchar_t  wc[ 8 ];
  4740.  
  4741.       mbstowcs(ws,"Blue Danube",12);
  4742.       mbstowcs(wc,"ab",3);
  4743.  
  4744.       result = wcspbrk( ws, wc);
  4745.  
  4746.       printf("The first occurrence of any of the characters \"%S\" in "
  4747.          "\"%S\" is \"%S\"\n", wc, ws, result);
  4748.  
  4749.       }
  4750.   /*******************  Output should be similar to:  *********************
  4751.  
  4752.   The first occurrence of any of the characters "ab" in "Blue Danube" is "anube"
  4753.  
  4754.   *************************************************************************/
  4755.  
  4756.  This example returns a pointer to the first occurrence in the array string of 
  4757.  either a or b. 
  4758.  
  4759.  
  4760. ΓòÉΓòÉΓòÉ 11.11. WCSRCHR -- Locates last occurence of wide character in a string ΓòÉΓòÉΓòÉ
  4761.  
  4762.  
  4763. Syntax 
  4764.  
  4765. #include <wchar.h>
  4766.  
  4767. wchar_t *wcsrchr(const wchar_t *ws, wint_t wi);
  4768.  
  4769. Description. 
  4770.  
  4771. The wcsrchr function locates the last occurrence of wi in the string pointed to 
  4772. by ws.  The terminating wchar_t null character is considered to be part of the 
  4773. string. 
  4774.  
  4775. The wcsrchr function returns a pointer to the character, or a NULL pointer if 
  4776. wi does not occur in the string. 
  4777. Related Information 
  4778.  
  4779.    o  wcschr  - Search wchar_t String for Given wchar_t 
  4780.    o  wcscspn  - Find Offset of First wchar_t Match 
  4781.    o  wcsspn  - Search wchar_t Characters in String 
  4782.    o  wcswcs  - Locate wchar_t Substring in wchar_t String 
  4783.    o  wcspbrk  - Locate wchar_t Characters in String 
  4784.    o  wchar.h 
  4785.  
  4786.  Example 
  4787.  
  4788.   #include <stdio.h>
  4789.   #include <wchar.h>
  4790.  
  4791.   int main(void) {
  4792.       wchar_t ws[40];
  4793.       wchar_t * ptr;
  4794.       wint_t    wi = (wint_t)'p';
  4795.  
  4796.       mbstowcs(ws,"computer program",19);
  4797.  
  4798.       ptr = wcschr( ws, wi );
  4799.  
  4800.       printf( "The first occurrence of %C in '%S' is '%S'\n", wi, ws, ptr );
  4801.  
  4802.       ptr = wcsrchr( ws, wi );
  4803.  
  4804.       printf( "The last occurrence of %C in '%S' is '%S'\n",  wi, ws, ptr );
  4805.       }
  4806.   /****************  Output should be similar to:  ******************
  4807.  
  4808.   The first occurrence of p in 'computer program' is 'puter program'
  4809.   The last occurrence of p in 'computer program' is 'program'
  4810.  
  4811.   *******************************************************************/
  4812.  
  4813.  This example compares the use of wcschr and wcsrchr. It searches the string 
  4814.  for the first and last occurrence of p in the wide character string. 
  4815.  
  4816.  
  4817. ΓòÉΓòÉΓòÉ 11.12. WCSSPN -- Finds lingth of wide character substring ΓòÉΓòÉΓòÉ
  4818.  
  4819.  
  4820. Syntax 
  4821.  
  4822. #include <wchar.h>
  4823.  
  4824. size_t wcsspn(const wchar_t *ws1, const wchar_t *ws2);
  4825.  
  4826. Description. 
  4827.  
  4828. The wcsspn function computes the number of wchar_t characters in the initial 
  4829. segment of the string pointed to by ws1, which consists entirely of wchar_t 
  4830. characters from the string pointed to by ws2. 
  4831.  
  4832. The wcsspn function returns the number of wchar_t characters in the segment. 
  4833. Related Information 
  4834.  
  4835.    o  wcschr  - Search wchar_t String for Given wchar_t 
  4836.    o  wcscspn  - Find Offset of First wchar_t Match 
  4837.    o  wcsrchr  - Locate wchar_t Character in String 
  4838.    o  wcsspn  - Search wchar_t Characters in String 
  4839.    o  wcswcs  - Locate wchar_t Substring in wchar_t String 
  4840.    o  wcspbrk  - Locate wchar_t Characters in String 
  4841.    o  wchar.h 
  4842.  
  4843.  Example 
  4844.  
  4845.   #include <stdio.h>
  4846.   #include <wchar.h>
  4847.  
  4848.   int main(void) {
  4849.       wchar_t  ws[20];
  4850.       wchar_t  source[8];
  4851.       int index;
  4852.  
  4853.       mbstowcs(ws,"cabbage",8);
  4854.       mbstowcs(source,"abc",4);
  4855.  
  4856.       index = wcsspn( ws, source );
  4857.  
  4858.       printf( "The first %d characters of \"%S\" are found in \"%S\"\n",
  4859.              index, ws, source );
  4860.       }
  4861.   /****************  Output should be similar to:  ******************
  4862.  
  4863.   The first 5 characters of "cabbage" are found in "abc"
  4864.  
  4865.   *******************************************************************/
  4866.  
  4867.  This example finds the first occurrence in the array string of a character 
  4868.  that is neither an a, b, nor c.  Because the string in this example is 
  4869.  cabbage, wcsspn returns 5, the index of the segment of cabbage before a 
  4870.  character that is not an a, b, or c. 
  4871.  
  4872.  
  4873. ΓòÉΓòÉΓòÉ 11.13. WCSTOK -- Converts wide-character strings to tokens ΓòÉΓòÉΓòÉ
  4874.  
  4875.  
  4876. Syntax 
  4877.  
  4878. #include <wchar.h>
  4879.  
  4880. wchar_t *wcstok(wchar_t *String1, const wchar_t *String2);
  4881.  
  4882. Description 
  4883.  
  4884. The wcstok function reads a wide-character string1 as a series of zero or more 
  4885. tokens and wide-character string2 as the set of characters serving as 
  4886. delimiters of the tokens in string1.  The tokens in string1 can be separated by 
  4887. one or more of the delimiters from string2.  The tokens in string1 can be 
  4888. located by a series of calls to wcstok. 
  4889.  
  4890. In the first call to wcstok for a given string1, wcstok searches for the first 
  4891. token in  string1, skipping over leading delimiters.  A pointer to the first 
  4892. token is returned. 
  4893.  
  4894. To read the next token from string1, call wcstok with a NULL string1 argument. 
  4895. A NULL string1 argument causes wcstok to search for the next token in the 
  4896. previous token string.  Each delimiter is replaced by a null character.  The 
  4897. set of delimiters can vary from call to call, so string2 can take any value. 
  4898.  
  4899. The first time wcstok is called, it returns a pointer to the first token in 
  4900. string1.  In later calls with the same token string, wcstok returns a pointer 
  4901. to the next token in the string.  A NULL pointer is returned when there are no 
  4902. more tokens.  All tokens are null-terminated. 
  4903. Parameters 
  4904.  
  4905.  String1   Contains a pointer to the wide-character string to be searched. 
  4906.  
  4907.  String2   Contains a pointer to the string of wide-character token delimiters. 
  4908.  
  4909.  Return Values 
  4910.  
  4911.  The wcstok subroutine returns a pointer to the first wide-character of a 
  4912.  token. A null pointer is returned if there is no token found. 
  4913.  Related Information 
  4914.  
  4915.    o  wcsspn 
  4916.    o  wcswcs 
  4917.    o  wcstoul 
  4918.    o  wcstol 
  4919.    o  wchar.h 
  4920.  
  4921.  Example 
  4922.  
  4923.   #include <stdio.h>
  4924.   #include <stdlib.h>
  4925.   #include <string.h>
  4926.   #include <wchar.h>
  4927.  
  4928.   int main(void) {
  4929.       wchar_t *wsList;
  4930.       wchar_t *wsToken;
  4931.       wchar_t *wsCodes;
  4932.  
  4933.       wsList  = (wchar_t *)calloc(80,sizeof(wchar_t));
  4934.       wsCodes = (wchar_t *)calloc(10,sizeof(wchar_t));
  4935.       wsToken = (wchar_t *)calloc(80,sizeof(wchar_t));
  4936.  
  4937.       mbstowcs(wsList, "abc,def.ghi;jk!lmnop",25);
  4938.       mbstowcs(wsCodes, ";,!.\0",5);
  4939.  
  4940.       /* the wide-character string pointed to by wsList is broken up
  4941.       into the tokens "abc", "def", "ghi", "jk" and "lmnop" ;
  4942.       the null terminator (\0) is encountered and execution stops    */
  4943.  
  4944.       wsToken = wcstok(wsList,wsCodes);
  4945.  
  4946.       do {
  4947.         printf("Token: %S\n", wsToken);
  4948.         wsToken = wcstok(NULL,wsCodes);
  4949.         } while (wsToken != NULL);
  4950.  
  4951.       free(wsList);
  4952.       free(wsCodes);
  4953.       free(wsToken);
  4954.       }
  4955.  
  4956.   /************************************************************************
  4957.  
  4958.   Output
  4959.  
  4960.   Token: abc
  4961.   Token: def
  4962.   Token: ghi
  4963.   Token: jk
  4964.   Token: lmnop
  4965.  
  4966.   ************************************************************************/
  4967.  
  4968.  Using a loop, the following example gathers tokens, deliminated by commas, 
  4969.  periods, semi-colons, or exclamation points, from  a string until no tokens 
  4970.  are left.  After processing the example returns the pointers to the tokens 
  4971.  abc, def, ghi, jk and lmnop. The next call to wcstok returns NULL and the loop 
  4972.  ends. 
  4973.  
  4974.  
  4975. ΓòÉΓòÉΓòÉ 11.14. WCSWCS -- Locate wide-character substring ΓòÉΓòÉΓòÉ
  4976.  
  4977.  
  4978. Syntax 
  4979.  
  4980. #include <wchar.h>
  4981.  
  4982. wchar_t *wcswcs(const wchar_t *string1, const wchar_t *string2);
  4983.  
  4984. Description. 
  4985.  
  4986. The wcswcs function locates the first occurrence in the string pointed to by 
  4987. string1 of the sequence of wchar_t characters (excluding the terminating 
  4988. wchar_t null character) in the string pointed to by string2. 
  4989.  
  4990. The wcswcs function returns a pointer to the located string or NULL if the 
  4991. string is not found.  If string2 points to a string with zero length, the 
  4992. function returns string1. 
  4993. Related Information 
  4994.  
  4995.    o  wcschr  - Search wchar_t String for Given wchar_t 
  4996.    o  wcscspn  - Find Offset of First wchar_t Match 
  4997.    o  wcspbrk  - Locate wchar_t Characters in String 
  4998.    o  wcsrchr  - Locate wchar_t Character in String 
  4999.    o  wcsspn  - Search wchar_t Characters in String 
  5000.    o  wchar.h 
  5001.  
  5002.  Example 
  5003.  
  5004.   #include <stdio.h>
  5005.   #include <wchar.h>
  5006.  
  5007.   #define SIZE 40
  5008.  
  5009.   int main(void) {
  5010.       wchar_t buffer1[SIZE];
  5011.       wchar_t * ptr;
  5012.       wchar_t wch[SIZE];
  5013.  
  5014.       mbstowcs(buffer1,"ski slope",SIZE);
  5015.       mbstowcs(wch,"sl",SIZE);
  5016.  
  5017.       ptr = wcswcs( buffer1, wch );
  5018.       printf( "The first occurrence of %S in '%S' is '%S'\n", wch, buffer1, ptr );
  5019.       }
  5020.   /****************  Output should be similar to:  ******************
  5021.  
  5022.   The first occurrence of sl in 'ski slope' is 'slope'
  5023.  
  5024.   *******************************************************************/
  5025.  
  5026.  This example finds the first occurrence of the wide character string pr in 
  5027.  buffer1. 
  5028.  
  5029.  
  5030. ΓòÉΓòÉΓòÉ 11.15. WCSWIDTH -- Determines the display width of wide character strings ΓòÉΓòÉΓòÉ
  5031.  
  5032.  
  5033. Syntax 
  5034.  
  5035. #include <wchar.h>
  5036.  
  5037. int wcswidth(const wchar_t *pwcs, size_t n);
  5038.  
  5039. Description 
  5040.  
  5041. The wcswidth subroutine determines the number of display columns to be 
  5042. occupied by the number of wide characters specified by the n parameter in the 
  5043. string pointed to by the pwcs parameter.  The LC_CTYPE category affects the 
  5044. behavior of the wcswidth  subroutine.  Fewer than the number of wide characters 
  5045. specified by the n parameter are counted if a null character is encountered 
  5046. first.  The wcswidth subroutine returns the number of display columns to be 
  5047. occupied by the number of wide characters (up to the terminat ing wide 
  5048. character null) specified by the n parameter (or fewer) in the string pointed 
  5049. to by the pwcs parameter.  A value of zero is returned if the pwcs parameter is 
  5050. a wide character null pointer or a pointer to a wide character null (that is, 
  5051. pwcs or *pwcs is null).  If the pwcs parameter points to an unusable wide 
  5052. character code, -1 is returned.  n Specifies the maximum number of wide 
  5053. characters whose display width is to be determined.  pwcs Contains a pointer to 
  5054. the wide character string. 
  5055. Related Information 
  5056.  
  5057.    o  wcwidth - Determines the display width of wide characters. 
  5058.    o  wchar.h - Header file for wide character function prototypes. 
  5059.  
  5060.  Example 
  5061.  
  5062.   #include <string.h>
  5063.   #include <stdlib.h>
  5064.   #include <wchar.h>
  5065.  
  5066.   #define  SIZE  80
  5067.  
  5068.   int main(void) {
  5069.       wchar_t pwcs[SIZE];
  5070.       int  retval,
  5071.       int  n;
  5072.  
  5073.       setlocale(LC_ALL, "");
  5074.  
  5075.       /* Let pwcs point to a wide character null terminated
  5076.       ** string. Let n be the number of wide characters whose
  5077.       ** display column width is to be determined.
  5078.       */
  5079.  
  5080.       mbstowcs(pwcs,"This is a test string",SIZE);
  5081.  
  5082.       retval = wcswidth( pwcs, n );
  5083.  
  5084.       if(retval == -1) {
  5085.         /* Error handling. Invalid wide character code
  5086.         ** encountered in the wide character string pwcs.
  5087.         */
  5088.         printf("Invalid wide    character code was    incountered in the    wide character    string\n");
  5089.         }
  5090.  
  5091.       else
  5092.         printf("The width of this wide character string \n %S \nis %d\n",pwcs,retval);
  5093.  
  5094.       }
  5095.  
  5096.  This example finds the display column width of a wide character string. 
  5097.  
  5098.  
  5099. ΓòÉΓòÉΓòÉ 11.16. WCTYPE -- Define character class ΓòÉΓòÉΓòÉ
  5100.  
  5101.  
  5102. Syntax 
  5103.  
  5104. #include <wchar.h>
  5105.  
  5106. char wctype(const char *charclass);
  5107.  
  5108. Description 
  5109.  
  5110. The wctype functions uses the character class names - 
  5111.  
  5112.  "alnum"    -  for the alpha numeric class. 
  5113.  
  5114.  "alpha"    -  for the alphabetic only class. 
  5115.  
  5116.  "cntrl"    -  for the control class. 
  5117.  
  5118.  "digit"    -  for the digit class. 
  5119.  
  5120.  "graph"    -  for the graphics character class. 
  5121.  
  5122.  "lower"    -  for the lower case character class. 
  5123.  
  5124.  "print"    -  for the printable character class. 
  5125.  
  5126.  "punct"    -  for the punctuation class. 
  5127.  
  5128.  "space"    -  for the space character class. 
  5129.  
  5130.  "upper"    -  for the upper case character class. 
  5131.  
  5132.  "xdigit"  -  for the digit or alpha character class. 
  5133.  
  5134.  "blank"    -  for the hexadecimal alpha numeric class. 
  5135.  to define the values of wctype_t according to the rules of the coded character 
  5136.  set defined by character type information in the program's locale (LC_CTYPE). 
  5137.  These values are valid untill changed by a call to setlocale(). 
  5138.  Related Information 
  5139.  
  5140.    o  iswctype 
  5141.    o  wchar.h 
  5142.  
  5143.  Example 
  5144.  
  5145.   #include <stdio.h>
  5146.   #include <wchar.h>
  5147.  
  5148.   #define UPPER_LIMIT   0xFF
  5149.  
  5150.   int main(void) {
  5151.       wint_t ch;
  5152.  
  5153.       for ( ch = 0; ch <= UPPER_LIMIT; ++ch ) {
  5154.         printf("\n%3d ", ch);
  5155.         printf("%#04x ", ch);
  5156.         printf("%3s ", iswctype(ch,wctype("alnum"))  ? "AN" : " ");
  5157.         printf("%2s ", iswctype(ch,wctype("alpha"))  ? "A"  : " ");
  5158.         printf("%2s",  iswctype(ch,wctype("cntrl"))  ? "C"  : " ");
  5159.         printf("%2s",  iswctype(ch,wctype("digit"))  ? "D"  : " ");
  5160.         printf("%2s",  iswctype(ch,wctype("graph"))  ? "G"  : " ");
  5161.         printf("%2s",  iswctype(ch,wctype("lower"))  ? "L"  : " ");
  5162.         printf(" %c",  iswctype(ch,wctype("blank"))  ? "B"  : " ");
  5163.         printf("%3s",  iswctype(ch,wctype("punct"))  ? "PU" : " ");
  5164.         printf("%2s",  iswctype(ch,wctype("space"))  ? "S"  : " ");
  5165.         printf("%3s",  iswctype(ch,wctype("print"))  ? "PR" : " ");
  5166.         printf("%2s",  iswctype(ch,wctype("upper"))  ? "U"  : " ");
  5167.         printf("%2s",  iswctype(ch,wctype("xdigit")) ? "X"  : " ");
  5168.         }
  5169.       }
  5170.  
  5171.  This example analyzes all characters between code 0x0 and code UPPER_LIMIT, 
  5172.  printing A for alphabetic characters, AN for alphanumerics, U for uppercase, L 
  5173.  for lowercase, D for digits, X for hexadecimal digits, S for spaces, PU for 
  5174.  punctuation, PR for printable characters, G for graphics characters, and C for 
  5175.  control characters. This example prints the code if printable. 
  5176.  
  5177.  The output of this example is a 256-line table showing the characters from 0 
  5178.  to 255 that possess the attributes tested. 
  5179.  
  5180.  
  5181. ΓòÉΓòÉΓòÉ 11.17. WCWIDTH -- Determines the display width of wide characters ΓòÉΓòÉΓòÉ
  5182.  
  5183.  
  5184. Syntax 
  5185.  
  5186. #include <wchar.h>
  5187.  
  5188. int wcwidth(wint_t wc);
  5189.  
  5190. Description 
  5191.  
  5192. The wcwidth subroutine determines the number of display columns to be occupied 
  5193. by the wide character specified by the wc parameter.  The LC_CTYPE subroutine 
  5194. affects the behavior of the wcwidth subroutine.  The wcwidth subroutine returns 
  5195. the number of display columns to be occupied by the WC parameter.  If the WC 
  5196. parameter is a wide character null, a value of 0 is returned.  If the WC 
  5197. parameter points to an unusable wide character code, -1 is returned.  wc 
  5198. Specifies a wide character. 
  5199. Related Information 
  5200.  
  5201.    o  wcswidth 
  5202.    o  wchar.h 
  5203.  
  5204.  Example 
  5205.  
  5206.   #include <stdlib.h>
  5207.   #include <string.h>
  5208.   #include <wchar.h>
  5209.  
  5210.   int main(void) {
  5211.       wchar_t wc = 0x41;
  5212.       int   retval;
  5213.  
  5214.       setlocale(LC_ALL, "");
  5215.  
  5216.       /* Let wc be the wide character whose
  5217.       ** display width is to be found.
  5218.       */
  5219.       retval= wcwidth( wc );
  5220.  
  5221.       if(retval == -1) {
  5222.         /*
  5223.         ** Error handling. Invalid wide character in wc.
  5224.         */
  5225.         printf("Invalid wide character\n");
  5226.         }
  5227.       else
  5228.         printf("The width of the wide character\n%C\nis %d\n",wc,retval);
  5229.       }
  5230.  
  5231.  This example finds the display column width of a wide character.