f******n 发帖数: 90 | 1 这是glibc 2.6 的实现.
/* Find the first occurrence in S of any character in ACCEPT. */
char *
strpbrk (s, accept)
const char *s;
const char *accept;
{
while (*s != '\0')
{
const char *a = accept; // *** my comment: unnecessary! ???
while (*a != '\0')
if (*a++ == *s)
return (char *) s;
++s;
}
return NULL;
}
I don't understand why there is an extra temp variable "a" defined at ***.
Why don't we just use accept? Anyway, changes made to accep | R***Z 发帖数: 1167 | 2 Because otherwise the result would be wrong, hehe
"accept" will be used again and again for all characters in s, in every
iteration you have to start from the beginning of "accept"
【在 f******n 的大作中提到】 : 这是glibc 2.6 的实现. : /* Find the first occurrence in S of any character in ACCEPT. */ : char * : strpbrk (s, accept) : const char *s; : const char *accept; : { : while (*s != '\0') : { : const char *a = accept; // *** my comment: unnecessary! ???
| f******n 发帖数: 90 | 3 I overlooked the outside loop. Thanks! |
|