我试着编写自己的strchr()方法实现.
它现在看起来像这样:
char *mystrchr(const char *s, int c) {
while (*s != (char) c) {
if (!*s++) {
return NULL;
}
}
return (char *)s;
}
Run Code Online (Sandbox Code Playgroud)
最后一行原来是
return s;
Run Code Online (Sandbox Code Playgroud)
但这不起作用,因为s是const.我发现需要这个演员(char*),但老实说我不知道我在那里做什么:(有人可以解释一下吗?