Skip to content

Instantly share code, notes, and snippets.

@derekli66
Created April 18, 2015 07:20
Show Gist options
  • Save derekli66/ac43ec404f0526bd41fb to your computer and use it in GitHub Desktop.
Save derekli66/ac43ec404f0526bd41fb to your computer and use it in GitHub Desktop.
The sample code to pointer position of specific char in a string.
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