Posted By

zava on 08/16/10


Tagged

textmate find token strpbrk


Versions (?)

strpbrk.c


 / Published in: C
 

  1. // Same function as strpbrk() in libc
  2. // Find the first occurrence in source of a character in chars (excluding NUL).
  3. char* find_char(const char* source, const char* chars)
  4. {
  5. // For better performance, put the source string and chars in the stack;
  6. // See strpbrk.c in libc, OpenBSD
  7. const char* s = source;
  8. while (*s++ != '\0')
  9. {
  10. const char *c = chars;
  11. while (*c++ != '\0')
  12. {
  13. if (*s == *c) return (char*)s;
  14. }
  15. }
  16. return NULL;
  17. }
  18.  
  19. int main (int argc, char const *argv[])
  20. {
  21. char* c = find_char("ABCDEF", "XRCQEF");
  22. if (c) printf("The result is [%c]n", *c);
  23. return 0;
  24. }

Report this snippet  

You need to login to post a comment.