Created
April 18, 2015 07:20
-
-
Save derekli66/ac43ec404f0526bd41fb to your computer and use it in GitHub Desktop.
The sample code to pointer position of specific char in a string.
This file contains hidden or 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
size_t strlength(char const *string) { | |
int length = 0; | |
while (*string++ != '\0') { | |
length += 1; | |
} | |
return length; | |
} | |
char *find_char(char const *source, char const *chars) { | |
char const *competitor = NULL; | |
char const *finding = NULL; | |
size_t sourceLen = strlength(source); | |
while (*(competitor = chars++) != '\0') { | |
while (*(finding = source++) != '\0' && *finding != *competitor); | |
source = source - (sourceLen + 1); | |
if (*finding != '\0') { | |
break; | |
} | |
} | |
return (char *)finding; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment