memstr.c

来自「一个C语言写的快速贝叶斯垃圾邮件过滤工具」· C语言 代码 · 共 28 行

C
28
字号
/* $Id: memstr.c,v 1.6 2005/01/09 04:24:21 m-a Exp $ *//** \file memstr.c * find a C string in memory * \author Matthias Andree * \date 2004 * GNU General Public License v2 */#include "memstr.h"/** find the C string \a needle in the \a n bytes starting with \a hay, * \return 0 if no match found, the pointer to the first byte otherwise. */void *memstr(const void *hay, size_t n, const char *needle){    unsigned const char *haystack = hay;    size_t l = strlen(needle);    while (n >= l) {	if (0 == memcmp(haystack, needle, l))	    return (void *)haystack;	haystack++;	n--;    }    return (void *)0;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?