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

后端 未结 6 1633
难免孤独
难免孤独 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:34

    int index = strchr(values,find)-values;
    

    Note, that if there's no find found, then strchr returns NULL, so index will be negative.

提交回复
热议问题