// 说明:参数和用法都类似strchr、strstr、memchr这些函数。
void* membin(const void* mem, unsigned int mem_count, const void* bin, unsigned int bin_count)
{
char* src = (char*)mem;
int max_cmp_count = (int)(mem_count - bin_count) + 1;
int i = 0;
if ( mem && bin && max_cmp_count > 0 )
{
for ( i = 0; i < max_cmp_count; ++i )
{
if ( 0 == memcmp(src, bin, bin_count) )
{
return (void*)src;
}
else
{
src += 1;
}
}
}
return NULL;
}
本文介绍了一个名为membin的函数,该函数类似于strchr、strstr、memchr等字符串搜索函数,用于在内存区域中查找指定模式的出现位置。文章详细解释了membin函数的工作原理和实现细节。
648

被折叠的 条评论
为什么被折叠?



