Is there a function in c that will return the index of a char in a char array?

后端 未结 6 1677
难免孤独
难免孤独 2021-01-01 14:20

Is there a function in c that will return the index of a char in a char array?

For example something like:

char values[] = \"0123456789ABCDEFGHIJKLMN         


        
6条回答
  •  青春惊慌失措
    2021-01-01 14:48

    What about strpos?

    #include 
    
    int index;
    ...
    index = strpos(values, find);
    

    Note that strpos expects a zero-terminated string, which means you should add a '\0' at the end. If you can't do that, you're left with a manual loop and search.

提交回复
热议问题