博客
关于我
浅谈strstr()实现
阅读量:278 次
发布时间:2019-03-01

本文共 498 字,大约阅读时间需要 1 分钟。

strstr 字符串匹配

strstr 字符串匹配功能描述

在第一个字符串中查找与第二个字符串完全相同的子串,如果存在,则返回第一个字符串中该子串的首地址。

该函数通过逐字符比较的方式实现匹配,确保两个字符串在相同位置上字符完全一致。如果匹配成功,返回第一个字符串中子串起始位置的指针;如果未找到匹配项,则返回NULL。

函数实现代码

char* my_strstr(char* str, char* sub) {	while (*str) {		if (*str != *sub) {			str++;		} else {			char* stri = str;			char* subi = sub;			while (*subi && *stri == *subi && *stri) {				subi++;				stri++;			}			if (*stri == '\0') {				return NULL;			}			if (*subi == '\0') {				return str;			} else {				str++;			}		}	}	return NULL;}

转载地址:http://cdno.baihongyu.com/

你可能感兴趣的文章
mysql 导入 sql 文件时 ERROR 1046 (3D000) no database selected 错误的解决
查看>>
mysql 导入导出大文件
查看>>
MySQL 导出数据
查看>>
mysql 将null转代为0
查看>>
mysql 常用
查看>>
MySQL 常用列类型
查看>>
mysql 常用命令
查看>>
Mysql 常见ALTER TABLE操作
查看>>
MySQL 常见的 9 种优化方法
查看>>
MySQL 常见的开放性问题
查看>>
Mysql 常见错误
查看>>
mysql 常见问题
查看>>
MYSQL 幻读(Phantom Problem)不可重复读
查看>>
mysql 往字段后面加字符串
查看>>
mysql 快照读 幻读_innodb当前读 与 快照读 and rr级别是否真正避免了幻读
查看>>
MySQL 快速创建千万级测试数据
查看>>
mysql 快速自增假数据, 新增假数据,mysql自增假数据
查看>>
MySql 手动执行主从备份
查看>>
Mysql 批量修改四种方式效率对比(一)
查看>>
Mysql 报错 Field 'id' doesn't have a default value
查看>>