[英]Characters and Strings in c with strpbrk
Given the followings : 鉴于以下内容:
char delimiters1[] = {' ' , '&' , '<' , '>'};
char delimiters2[] = " &<>";
If I use the C
function strpbrk
with delimiters1
and delimiters2
, the results would be the same ? 如果我使用带有
delimiters1
和delimiters2
的C
函数strpbrk
,结果会是一样的吗?
I've tested both of them with something like 20 inputs , and I got the same output for both . 我用20个输入测试了它们,我得到了两个相同的输出。
Am I wrong ? 我错了吗 ?
thanks . 谢谢 。
char delimiters1[] = {' ' , '&' , '<' , '>'};
should be: 应该:
char delimiters1[] = {' ' , '&' , '<' , '>', 0};
It may work few times. 它可能会工作几次。 But sting should be null-terminated.
但刺痛应该是空终止的。 Otherwise, how will strpbrk will know the end of chars to be searched?
否则,strpbrk将如何知道要搜索的字符的结尾?
This is the snippet of strbrk() : 这是strbrk()的片段:
while (*s1)
{
for (c = s2; *c; c++)
{
if (*s1 == *c)
break;
}
if (*c)
break;
s1++;
}
Where c is the pointer to the char-set. 其中c是指向char-set的指针。 As you can clearly see that at some point
*c
should be null for the program to work correctly. 您可以清楚地看到,在某些时候,
*c
应为null,以使程序正常工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.