String.indexOf function in C

前端 未结 7 1384
Happy的楠姐
Happy的楠姐 2020-11-30 06:41

Is there a C library function that will return the index of a character in a string?

So far, all I\'ve found are functions like strstr that will return the found cha

相关标签:
7条回答
  • 2020-11-30 07:11

    I think that

    size_t strcspn ( const char * str1, const char * str2 );

    is what you want. Here is an example pulled from here:

    /* strcspn example */
    #include <stdio.h>
    #include <string.h>
    
    int main ()
    {
      char str[] = "fcba73";
      char keys[] = "1234567890";
      int i;
      i = strcspn (str,keys);
      printf ("The first number in str is at position %d.\n",i+1);
      return 0;
    }
    
    0 讨论(0)
提交回复
热议问题