strchr()和strpbrk()有什么不同。我找不到它们之间的任何区别。
strpbrk()
#include <stdio.h>
#include <string.h>
int main()
{
char str1[30] = "New Delhi is awesome city", str2[10] = "an";
char *st;
st = strpbrk(str1, str2);
printf("%s"st);
return 0;
}输出:awesome city
strchr()
#include <stdio.h>
#include <string.h>
int main()
{
char str1[] = "New Delhi is awesome city", ch = 'a';
char *chpos;
chpos = strchr(str1, ch);
if(chpos)
printf("%s",chpos);
return 0;
}输出:awesome city
发布于 2016-10-07 01:52:21
文档很清楚。来自strchr()和strpbrk()
char *strpbrk(const char *s, const char *accept);
The strpbrk() function locates the first occurrence in the string s
of any of the bytes in the string accept.
char *strchr(const char *s, int c);
The strchr() function returns a pointer to the first occurrence of
the character c in the string s.基本上,strpbrk()允许您指定要搜索的多个字符。在您的示例中,strchr()和strpbrk()都在找到字符'a'后停止,但这并不意味着它们做了同样的事情!
https://stackoverflow.com/questions/39902498
复制相似问题