您需要等效于 strstr 的东西,它适用于一般数组。这是我从你的问题中假设的。没有你可能发现的 memstr,所以你必须自己写。
像这样的东西:
size_t memstr(const unsigned char* arr, size_t length, const unsigned char* tofind, size_t flength) {
for(size_t i = 0; i < length-flength; ++i) {
if(memcmp(arr+i, tofind, flength) == 0)
return i;
}
return -1; //highest possible unsigned value - eg std::string::npos often implemented like this.
}
int main() {
const unsigned char arr1[] = {1,2,3,4,5,6,7,8,9,0,3,3,3,3,4,4,4,4,4};
size_t sz = sizeof(arr1) / sizeof(arr1[0]);
const unsigned char fnd[] = {3,3,3};
size_t where = memstr(arr1, sz, fnd, 3);
return 0;
}