3.10 Example: NWUnicodeToLocal with Unmappable Character

   /* exuu2l_2.c  -  NWUnicodeToLocal example with unmappable character */ 
   #define NWL_EXCLUDE_TIME 
   #define NWL_EXCLUDE_FILE 
   #include <nwlocale.h> 
   #include <unicode.h> 
   #include <string.h> 
   #include <assert.h> 
   void main() 
   { 
      LCONV lconv; 
      nint err; 
      nptr h = NULL; 
      unicode src[5] = {’a’, 0xFFFD, ’c’, ’d’, 0};   /* Unmappable char */ 
      nuint8 dest[5]; 
      nuint8 noMap = 0;     /* Use the default replacement char. */ 
      nuint len; 
   
   /* Win32 platforms ignore noMap and use the Windows default char (’?’). 
      Non-win32 platforms use the given noMap character, or if it is zero, 
      uses the default nomap character from the Novell rules table, 
      which for US English, is 0xFD on NLM
   */
    
   #ifdef WIN32 
      nuint8 expect[5]  = {’a’, ’?’, ’c’, ’d’, 0};   /* Win32 output */ 
   #elif defined NWWIN 
      nuint8 expect[5]  = {’a’, 0x03, ’c’, ’d’, 0};  /* NLM output */ 
   #endif 
   
      /* Get the country ID and code page from the operating system. */ 
      NWLlocaleconv(&lconv);  
      err = NWInitUnicodeTables(lconv.country_id, lconv.code_page); 
      assert (err == 0); 
      err = NWGetUnicodeToLocalHandle(&h); 
      assert (err == 0); 
      err = NWUnicodeToLocal(h, dest, sizeof(dest), src, noMap, &len); 
      assert (err == 0); 
      assert (strcmp(dest, expect) == 0);  /* Local output string */ 
      assert (len == 5);                     /* Output size includes null */ 
      NWFreeUnicodeTables(); 
   }