Created
April 29, 2012 14:50
-
-
Save abevoelker/2550928 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DEF VAR mString AS MEMPTR NO-UNDO. | |
DEF VAR iCheckAddr AS INT NO-UNDO. | |
DEF VAR cSentence AS CHAR NO-UNDO INITIAL "The quick brown dog jumps over the lazy fox". | |
SET-SIZE(mString) = LENGTH(cSentence) + 1. /* Extra one is for \0 byte that gets put @ end */ | |
PUT-STRING(mString, 1) = cSentence. | |
RUN memchr(GET-POINTER-VALUE(mString) + 4, | |
ASC("b"), | |
LENGTH(cSentence) + 1, | |
OUTPUT iCheckAddr). | |
IF iCheckAddr = 0 THEN | |
MESSAGE "Char not found in string". | |
ELSE DO: | |
DEF VAR iIndex AS INT NO-UNDO. | |
iIndex = iCheckAddr - GET-POINTER-VALUE(mString). | |
MESSAGE SUBSTITUTE("Char found at (0-based) position &1", | |
iIndex). | |
END. | |
FINALLY: | |
SET-SIZE(mString) = 0. | |
END. | |
PROCEDURE memchr EXTERNAL "msvcrt.dll" CDECL: | |
DEFINE INPUT PARAMETER str_ptr AS LONG. | |
DEFINE INPUT PARAMETER char_val AS LONG. | |
DEFINE INPUT PARAMETER check_bytes AS UNSIGNED-LONG. | |
DEFINE RETURN PARAMETER ret_ptr AS LONG. | |
END PROCEDURE. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment