首页 > 编程语言 > 详细

【c语言】模拟库函数strstr

时间:2015-07-04 12:40:46      阅读:242      评论:0      收藏:0      [点我收藏+]
//  模拟库函数strstr

#include <stdio.h>
#include <assert.h>

const char* my_strstr(const char *parent, const char *child)
{
	const char *pgo = parent;
	const char *cgo = child;
	const char *pgos = parent;
	assert(parent != NULL && child != NULL);
	if (!*child)
	{
		return NULL;
	}
	while (*pgo)
	{
		pgo = pgos;
		cgo = child;
		while (*pgo == *cgo && *pgo && *cgo)
		{
			pgo++;
			cgo++;
		}
		if (*cgo == '\0')
			return pgos;
		pgos++;
	}
	return NULL;
}
int main()
{
	printf("%s\n", my_strstr("hhhww", "hhww"));
	printf("%s\n", my_strstr("zhaoyaqian","aoya"));
	printf("%s\n", my_strstr("abc", "aefg"));
	return 0;
}




技术分享



版权声明:本文为博主原创文章,未经博主允许不得转载。

【c语言】模拟库函数strstr

原文:http://blog.csdn.net/zhaoyaqian552/article/details/46754463

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!