WinPrevChar - Example Code

This example uses WinPrevChar to return a pointer to the previous character in a string.

#define INCL_DOSNLS
#define INCL_WINCOUNTRY
#define CURRENT_COUNTRY 0
#include <OS2.H>
#include <stdio.h>

main()
{
  HAB hab;                              /* Anchor-block handle      */
  char string[] = "ABCDEFGHIJ";
  char *ptoE = &string[4];
  char *ptoD;
  ULONG   CodePage;                     /* List returned            */
  ULONG  DataLength;                    /* Length of list returned  */
  COUNTRYCODE Country;
  COUNTRYINFO CtryBuffer;

  Country.country = CURRENT_COUNTRY;

  DosQueryCp((ULONG)2,
             &CodePage,             /* Get code page identifier */
             &DataLength);

  /* First WORD contains the codepage */
  Country.codepage = (ULONG)HIUSHORT(CodePage);

  /* Get the corresponding country code */
  DosQueryCtryInfo(sizeof(CtryBuffer),  /* Length of data area      */
                   &Country,        /* Input data structure     */
                   &CtryBuffer,     /* Data area to be filled   */
                   &DataLength);    /* Length of data           */

  /* A pointer should be returned to character "D" in the string */
  ptoD = WinPrevChar(hab,
                     (ULONG)CodePage,
                     (ULONG)CtryBuffer.country,
                     (PSZ)string,
                     ptoE);             /* Pointer to character "E" */

  printf(ptoE);
}


[Back: WinPrevChar - Related Functions]
[Next: WinPrevChar - Topics]