/*****************************************************************************/
/***     Include files                                                     ***/
/*****************************************************************************/

#include <stdio.h>                      /* Standard IO functions.            */

#include <wchar.h>                      /* I18N library.                     */
#include <locale.h>                     /* Locale definitions.               */

/*****************************************************************************/
/***     Show the scanning and printing functions                          ***/
/*****************************************************************************/

void scan_print_functions(void)
{
  wchar_t w_char;                       /* A wide character.                 */
  wchar_t w_string[100];                /* A wide string.                    */
  char    t_char;                       /* A character.                      */
  char    t_string[200], t_string2[200],/* Four strings used below.          */
          t_string3[200], t_string4[200];
  FILE    *in_file, *out_file;          /* Input and output file handles.    */

                                        /* Set the locale for the program.   */
  setlocale(LC_ALL, "");

                                        /* Print request.                    */
                                        /* Scan in both a single-byte        */
                                        /*  multi-byte (1 or more bytes)     */
                                        /*  NOTE:  The scanf                 */
                                        /*  routine automatically converts   */
                                        /*  the character to a wchar_t for   */
                                        /*  you.                             */
                                        /* Print out results.  NOTE:  The    */
                                        /*  capital letters are used for     */
                                        /*  wide character equivilents.      */
  printf("\nEnter a single-byte character and a mylti-byte character:\n");
  scanf("%c %C", &t_char, &w_char);
  printf("You entered: '%c' and '%C'\n", t_char, w_char);

                                        /* Convert a float to a string being */
                                        /*  aware of the radix character.    */
                                        /* Print it out.                     */
  sprintf(t_string,
          "\nThis is a culturally formatted floating point: %f\n", 123.45);
  printf(t_string);

                                        /* Copy a literal into a string.     */
                                        /* Scan from the string to find the  */
                                        /*  missing word.                    */
                                        /* Print (into another string) the   */
                                        /*  results.                         */
                                        /* Print out the generated string.   */
  strcpy(t_string, "This is a wide string!");
  sscanf(t_string, "This %S %s wide string!", w_string, t_string2);
  sprintf(t_string3, "Scanned strings are: '%S' and '%s'\n",
          w_string, t_string2);
  printf("\n%s", t_string3);

                                        /* Open the input file.              */
                                        /* Scan (from file) three strings    */
                                        /*  (which happen to be positional   */
                                        /*  argument holders).               */
                                        /* Close the file.                   */
                                        /* Generate a new string from the    */
                                        /*  three strings read in.           */
                                        /* Create a new string using the     */
                                        /*  generated string as the format.  */
  in_file = fopen("INPUT", "r");
  fscanf(in_file, "%s %s %s", t_string, t_string2, t_string3);
  fclose(in_file);
  sprintf(t_string4, "%s %s %s", t_string, t_string2, t_string3);
  sprintf(t_string, t_string4, "first_string", "second_string", "third_string");

                                        /* Open the output file.             */
                                        /* Print the results to the file.    */
                                        /* Close the file.                   */
  out_file = fopen("OUTPUT", "w");
  fprintf(out_file, "Output of positional string: %s\n", t_string);
  fclose(out_file);
}

/*****************************************************************************/
/***     Main program                                                      ***/
/*****************************************************************************/

void main(void)
{
                                        /* Scan and print functions.         */
  scan_print_functions();
}
