c中是否有一个函数将返回char数组中char的索引?
例如:
char values[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
char find = 'E';
int index = findInedexOf( values, find );
发布于 2018-04-24 13:47:13
strchr
将指针返回到第一个匹配项,所以要找到索引,只需将起始指针作为偏移量。例如:
char values[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
char find = 'E';
const char *ptr = strchr(values, find);
if(ptr) {
int index = ptr - values;
// do something
}
发布于 2018-04-24 14:37:20
https://stackoverflow.com/questions/-100003963
复制相似问题