Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save outlinepix/dadb9ed30067a8546063191d3065b33a to your computer and use it in GitHub Desktop.
Save outlinepix/dadb9ed30067a8546063191d3065b33a to your computer and use it in GitHub Desktop.
C language of index0f() function of javascript.
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