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选择器一
在HTML中,通过各种各样的属性可以给元素增加很多附加的信息,了解和掌握css3一些的选择器,是很有必要的. 属性选择器示例: <div><a href="xxx.pdf& ...
- 简单风格 在线音乐播放器(支持wav,MP3等)
找了两天终于找到了,支持wav,MP3,其他格式没有测试. 1.修复了jQuery判断ie的bug, 2.修复播放循环 下载地址: http://pan.baidu.com/s/1o6upwHs
- jQueryr .on方法解析
.On() 其实.bind(), .live(), .delegate()都是通过.on()来实现的,.unbind(), .die(), .undelegate(),也是一样的都是通过.off()来 ...
- php 随机显示图片的函数(实例)
转自:http://www.jbxue.com/article/12695.html 发布:thatboy 来源:Net [大 中 小] 本文分享一个php实现的随机显示图片的函数,可 ...
- 普通用户开启AUTOTRACE 功能
AUTOTRACE是一个SQL*Plus工具,用于跟踪SQL的执行计划,收集执行时所耗用资源的统计信息.系统账户本身具有AUTOTRACE,其他账户需要通过手动赋予 一. 用系统账户登录(DBA) S ...
- C++程序员笔试复习概要(一)
第8章 类和对象的创建 [内容提要] 类和对象 构造函数和析构函数 对象数组与对象指针 静态成员 友元 静态函数 虚函数 [重点与难点] 8.1 类和对象 8.1.1 类的定义 类实质上是用户 ...
- 《WPF程序设计指南》读书笔记——第1章 应用程序与窗口
1.空白WPF项目的创建: 1)新建项目:在VS2010中,文件-新建-项目-visual c#-windows-空项目: 2)添加引用:PresentationFramework,Presentat ...
- 干货CentOS6.5_Nginx1.40_Php5.57_MySQL5.5.35编译安装全记录
http://www.unixdo.com/Unix_Linux/CentOS65_Nginx140_Php557_MySQL5535.html 如果是编译升级php,之前做过nginx的虚拟主机配置 ...
- Unity3d之Http通讯GET方法和POST方法
(一)GET方法 IEnumerator SendGet(string _url) { WWW getData = new WWW(_url); yield return getData; if(ge ...
- Flume的Avro Sink和Avro Source研究之一: Avro Source
问题 : Avro Source提供了怎么样RPC服务,是怎么提供的? 问题 1.1 Flume Source是如何启动一个Netty Server来提供RPC服务. 由GitHub上avro-rpc ...