/ Published in: C
Expand |
Embed | Plain Text
// Same function as strpbrk() in libc // Find the first occurrence in source of a character in chars (excluding NUL). char* find_char(const char* source, const char* chars) { // For better performance, put the source string and chars in the stack; // See strpbrk.c in libc, OpenBSD const char* s = source; while (*s++ != '\0') { const char *c = chars; while (*c++ != '\0') { if (*s == *c) return (char*)s; } } return NULL; } int main (int argc, char const *argv[]) { char* c = find_char("ABCDEF", "XRCQEF"); return 0; }
You need to login to post a comment.
