Last active
August 8, 2022 10:54
-
-
Save outlinepix/dadb9ed30067a8546063191d3065b33a to your computer and use it in GitHub Desktop.
C language of index0f() function of javascript.
This file contains 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
int indexOf(void *word, void *chars) | |
{ | |
char *result = strstr(word, chars); | |
if (result == NULL) | |
{ | |
printf("%s\n", "Not found"); | |
return -1; | |
} | |
char *p = word; | |
char *q = chars; | |
int i = 0; | |
while (*p != '\0') | |
{ | |
while (*q != '\0') | |
{ | |
if (*p == *q) | |
{ | |
return i; | |
} | |
q++; | |
} | |
p++; | |
i++; | |
q = chars; | |
} | |
return -1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment