Skip to content

Instantly share code, notes, and snippets.

@iamarkdev
Last active December 1, 2016 12:14
Show Gist options
  • Save iamarkdev/4ba07a8357075d93b26e89b65cc9f7e3 to your computer and use it in GitHub Desktop.
Save iamarkdev/4ba07a8357075d93b26e89b65cc9f7e3 to your computer and use it in GitHub Desktop.
#include <stdio.h>
// return the index of the first occurrence of any character in matching occuring in string. -1 if none.
int any(char string[], char matching[]) {
for (int i = 0; string[i] != '\0'; i++) {
for (int j = 0; matching[j] != '\0'; j++) {
if (string[i] == matching[j]) {
return i;
}
}
}
return -1;
}
int main() {
printf("%d\n", any("this is a test yo", "y"));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment