C语言字符串查找函数
#include <string.h>
#include <stdio.h> char * string_search(char long_str[], char short_str[])
{//author: emanlee
char *pl, *qs;
long is_identical, long_length, short_length;
long position, ii; long_length=strlen(long_str);
short_length=strlen(short_str); if (long_length<short_length)
{
printf("ERROR\n");
return NULL;
} for (position=; position<long_length-short_length+; position++)
{
pl=long_str+position;
qs=short_str;
is_identical=; for (ii=; ii<short_length; ii++)
{
if (*pl != *qs)
{
is_identical=;
break;
} pl++;
qs++;
} if (is_identical==)
{
return long_str+position;
} } return NULL; } char * string_search_postion(char long_str[], char short_str[], long start_position)
{//author: emanlee
char *pl, *qs;
long is_identical, long_length, short_length;
long position, ii; long_length=strlen(long_str);
short_length=strlen(short_str); if (long_length<short_length)
{
printf("ERROR\n");
return NULL;
} for (position=start_position; position<long_length-short_length+; position++)
{
pl=long_str+position;
qs=short_str;
is_identical=; for (ii=; ii<short_length; ii++)
{
if (*pl != *qs)
{
is_identical=;
break;
} pl++;
qs++;
} if (is_identical==)
{
return long_str+position;
} } return NULL; } char * string_search_pointer_postion(char long_str[], char short_str[], char * start_position)
{//author: emanlee
char *pl, *qs;
long is_identical, long_length, short_length;
long position, ii; long_length=strlen(long_str);
short_length=strlen(short_str); if (long_length<short_length)
{
printf("ERROR\n");
return NULL;
} for (position=(long)(start_position-long_str); position<long_length-short_length+; position++)
{
pl=long_str+position;
qs=short_str;
is_identical=; for (ii=; ii<short_length; ii++)
{
if (*pl != *qs)
{
is_identical=;
break;
} pl++;
qs++;
} if (is_identical==)
{
return long_str+position;
} } return NULL; } void main()
{
char a[]="";
char b[]="";
char *p; p=string_search(a,b); printf("%s\n", string_search(a,b));
printf("%s\n", string_search_postion(a,b,));
printf("%s\n", string_search_pointer_postion(a,b,p+)); }
C语言字符串查找函数的更多相关文章
- 转:C语言字符串操作函数 - strcpy、strcmp、strcat、反转、回文
转自:C语言字符串操作函数 - strcpy.strcmp.strcat.反转.回文 C++常用库函数atoi,itoa,strcpy,strcmp的实现 作者:jcsu C语言字符串操作函数 1. ...
- php中常用的字符串查找函数strstr()、strpos()实例解释
string strstr ( string $haystack , mixed $needle [, bool $before_needle = false ] ) 1.$haystack被查找的字 ...
- C/C++字符串查找函数
C/C++ string库(string.h)提供了几个字符串查找函数,如下: memchr 在指定内存里定位给定字符 strchr 在指定字符串里定位给定字符 strcspn 返回在字符串str1里 ...
- Strsafe.h:更安全的C语言字符串处理函数
原文出处:Strsafe.h: Safer String Handling in C 作者:Michael Howard 编译:王凌峰 在微软公司举行的Microsoft Windows Securi ...
- C/C++字符串查找函数 <转>
C/C++ string库(string.h)提供了几个字符串查找函数,如下: memchr 在指定内存里定位给定字符 strchr 在指定字符串里定位给定字符 strcspn 返回在字符串str1里 ...
- C语言字符串操作函数 - strcpy、strcmp、strcat、反转、回文
原文:http://www.cnblogs.com/JCSU/articles/1305401.html C语言字符串操作函数 1. 字符串反转 - strRev2. 字符串复制 - strcpy3. ...
- php字符串查找函数 php查找字符串中出现的次数函数substr_count,判断字符串中是否包含另一个字符串函数strpos
php字符串查找函数 php查找字符串中出现的次数函数substr_count,判断字符串中是否包含另一个字符串函数strpossubstr_count($haystack, $needle [,$o ...
- C语言字符串操作函数整理
整理C语言字符串相关的函数,以程序方式验证,以注释方式做说明. #include<stdio.h> #include<string.h> #include<stdlib. ...
- C语言字符串处理函数
函数名: strcpy 功 能: 拷贝一个字符串到另一个 用 法: char *stpcpy(char *destin, char *source); 程序例: #include < ...
随机推荐
- 纯CSS3代码实现简单的图片轮播
以4张图片为例:1.基本布局:将4张图片左浮动横向并排放入一个div容器内,图片设置统一尺寸,div宽度设置4个图片的总尺寸,然后放入相框容器div,相框设置1个图片的大小并设置溢出隐藏,以保证正确显 ...
- undefined local variable or method ‘xxx’ for #<RSpec::Core::ExampleGroup::Nested_1::Nested_1:0xbc88d6c>错误解决方案
官方文档如下: https://github.com/rspec/rspec-rails/blob/master/Capybara.md Capybara 2.0 To use Capybara 2. ...
- php微信支付(仅pc端扫码支付模式二)详细步骤.----仅适合第一次做微信开发的程序员
本人最近做了微信支付开发,是第一次接触.其中走了很多弯路,遇到的问题也很多.为了让和我一样的新人不再遇到类似的问题,我把我的开发步骤和问题写出来,以供参考. 开发时间是2016/8/10,所以微信支付 ...
- 收录一个简单的css类库
/* CSS liberary */.yahei { font-family: "Microsoft Yahei", "Tahoma", "Si ...
- 插入排序(insertion_sort)
最简单的排序算法,又称插值排序,原理类似于打扑克牌时把摸到的牌插入手中已有序牌的过程. void insertion_sort(int* A ,int n){ int i,j,key; ;i < ...
- sql之表连接 筛选条件放在 连接外和放在连接里的区别
使用一个简单的例子,说明他们之间的区别 使用的表:[Sales.Orders]订单表和[Sales.Customers]客户表,和上一篇博客的表相同 业务要求:查询出 : 所有的用户 在 2012-1 ...
- 域名的a记录转过来他的公网ip
首先 客户要我把域名 和项目进行绑定客户需要提供万网或者新网的账户,登进去域名管理 选项域名管理的A记录定向到那个公网ip上 与服务器做绑定然后 在服务器的iis 上 加个主机头 输入主机头名称 也 ...
- poj 2186 Popular Cows (强连通分量+缩点)
http://poj.org/problem?id=2186 Popular Cows Time Limit: 2000MS Memory Limit: 65536K Total Submissi ...
- maven+mybatis-generator插件反向生成源代码
通过maven+mybatis-generator插件反向生成源代码,如有一个table表为resource,那么将自动生成这样三个文件:Resource.java类.ResourceMapper.j ...
- c++ 字符串工具类
#include <string> #include "util.h" namespace strtool{ std::string trim(const std::s ...