home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / i18nv104.zip / SAMPLE / SCAN / SCAN.C < prev    next >
C/C++ Source or Header  |  1996-02-13  |  5KB  |  91 lines

  1. /*****************************************************************************/
  2. /***     Include files                                                     ***/
  3. /*****************************************************************************/
  4.  
  5. #include <stdio.h>                      /* Standard IO functions.            */
  6.  
  7. #include <wchar.h>                      /* I18N library.                     */
  8. #include <locale.h>                     /* Locale definitions.               */
  9.  
  10. /*****************************************************************************/
  11. /***     Show the scanning and printing functions                          ***/
  12. /*****************************************************************************/
  13.  
  14. void scan_print_functions(void)
  15. {
  16.   wchar_t w_char;                       /* A wide character.                 */
  17.   wchar_t w_string[100];                /* A wide string.                    */
  18.   char    t_char;                       /* A character.                      */
  19.   char    t_string[200], t_string2[200],/* Four strings used below.          */
  20.           t_string3[200], t_string4[200];
  21.   FILE    *in_file, *out_file;          /* Input and output file handles.    */
  22.  
  23.                                         /* Set the locale for the program.   */
  24.   setlocale(LC_ALL, "");
  25.  
  26.                                         /* Print request.                    */
  27.                                         /* Scan in both a single-byte        */
  28.                                         /*  multi-byte (1 or more bytes)     */
  29.                                         /*  NOTE:  The scanf                 */
  30.                                         /*  routine automatically converts   */
  31.                                         /*  the character to a wchar_t for   */
  32.                                         /*  you.                             */
  33.                                         /* Print out results.  NOTE:  The    */
  34.                                         /*  capital letters are used for     */
  35.                                         /*  wide character equivilents.      */
  36.   printf("\nEnter a single-byte character and a mylti-byte character:\n");
  37.   scanf("%c %C", &t_char, &w_char);
  38.   printf("You entered: '%c' and '%C'\n", t_char, w_char);
  39.  
  40.                                         /* Convert a float to a string being */
  41.                                         /*  aware of the radix character.    */
  42.                                         /* Print it out.                     */
  43.   sprintf(t_string,
  44.           "\nThis is a culturally formatted floating point: %f\n", 123.45);
  45.   printf(t_string);
  46.  
  47.                                         /* Copy a literal into a string.     */
  48.                                         /* Scan from the string to find the  */
  49.                                         /*  missing word.                    */
  50.                                         /* Print (into another string) the   */
  51.                                         /*  results.                         */
  52.                                         /* Print out the generated string.   */
  53.   strcpy(t_string, "This is a wide string!");
  54.   sscanf(t_string, "This %S %s wide string!", w_string, t_string2);
  55.   sprintf(t_string3, "Scanned strings are: '%S' and '%s'\n",
  56.           w_string, t_string2);
  57.   printf("\n%s", t_string3);
  58.  
  59.                                         /* Open the input file.              */
  60.                                         /* Scan (from file) three strings    */
  61.                                         /*  (which happen to be positional   */
  62.                                         /*  argument holders).               */
  63.                                         /* Close the file.                   */
  64.                                         /* Generate a new string from the    */
  65.                                         /*  three strings read in.           */
  66.                                         /* Create a new string using the     */
  67.                                         /*  generated string as the format.  */
  68.   in_file = fopen("INPUT", "r");
  69.   fscanf(in_file, "%s %s %s", t_string, t_string2, t_string3);
  70.   fclose(in_file);
  71.   sprintf(t_string4, "%s %s %s", t_string, t_string2, t_string3);
  72.   sprintf(t_string, t_string4, "first_string", "second_string", "third_string");
  73.  
  74.                                         /* Open the output file.             */
  75.                                         /* Print the results to the file.    */
  76.                                         /* Close the file.                   */
  77.   out_file = fopen("OUTPUT", "w");
  78.   fprintf(out_file, "Output of positional string: %s\n", t_string);
  79.   fclose(out_file);
  80. }
  81.  
  82. /*****************************************************************************/
  83. /***     Main program                                                      ***/
  84. /*****************************************************************************/
  85.  
  86. void main(void)
  87. {
  88.                                         /* Scan and print functions.         */
  89.   scan_print_functions();
  90. }
  91.