strchrC标准库中的函数在char字符串中查找a ,但其签名需要int搜索字符.在我发现的这两个实现中,实现将其转换int为char:
char *strchr(const char *s, int c) {
while (*s != (char)c)
if (!*s++)
return 0;
return (char *)s;
}
char *strchr(const char *s, int c) {
while (*s && *s != (char)c)
s++;
if (*s == c)
return (char *)s;
return NULL;
}
Run Code Online (Sandbox Code Playgroud)
有谁知道为什么?为什么不把a char作为参数呢?