AnsiPrev

2.x

  LPSTR AnsiPrev(lpchStart, lpchCurrentChar)    
  LPCSTR lpchStart; /* address of first character */
  LPCSTR lpchCurrentChar; /* address of current character */

The AnsiPrev function moves to the previous character in a string.

Parameters

lpchStart

Points to the beginning of the string.

lpchCurrentChar

Points to a character in a null-terminated string.

Return Value

The return value points to the previous character in the string, or to the first character in the string if the lpchCurrentChar parameter is equal to the lpchStart parameter.

Comments

The AnsiPrev function can be used to move through strings where each character is a single byte, or through strings where each character is two or more bytes (such as strings that contain characters from a Japanese character set).

This function can be very slow, because the string must be scanned from the beginning to determine the previous character. Wherever possible, the AnsiNext function should be used instead of this function.

Example

The following example uses the AnsiNext and AnsiPrev functions to change every occurrence of the characters '\&' in a string to a single newline character:

/* Find ampersands. */

for (lpsz = lpszTest; *lpsz != '\0'; lpsz = AnsiNext(lpsz)) {

    /* Check the previous character. */

    if (*lpsz == '&' &&
            *(lpsz2 = AnsiPrev(lpszTest, lpsz)) == '\\') {
        lstrcpy(lpsz2, lpsz);
        *lpsz2 = '\n';
    }
}

See Also

AnsiNext