Redian新闻
>
C库函数:strpbrk() 的实现一问
avatar
C库函数:strpbrk() 的实现一问# Programming - 葵花宝典
f*n
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
avatar
R*Z
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! ???

avatar
f*n
3
I overlooked the outside loop. Thanks!
相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。