(求帮助)(读取访问权限冲突)模拟实现找子字符串函数my_strstr

时间:2023-03-14 22:00:12

此代码会出现:引发了异常: 读取访问权限冲突,不知道为什么,有知道的吗,希望解决下

#include<stdio.h>
#include<assert.h>

char* my_strstr(const char* arr1, const char* arr2) {
assert(arr1);
assert(arr2);
char* pa = NULL;
char* pb = NULL;
char* find = (char*)arr1;
if (*arr2 == '\0') {
return (char*)arr1;
}
while (*find) {
pa = find;
pb = (char*)arr2;
while ((*pa == *pa) && *pa && *pb) {
pa++;
pb++;
}
if (*pb == '\0') {
return find;
}
if (*pa == '\0') {
return NULL;
}
find++;
}
return NULL;
}
int main() {
char arr1 = "abbbcd";
char arr2 = "bbcd";
//模拟实现找子字符串函数my_strstr
char* ret = my_strstr(arr1, arr2);
if (ret == NULL) {
printf("未能找到");
}
else {
printf("找到了,%s",ret);
}
return 0;
}