#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语言字符串查找函数的更多相关文章

  1. 转:C语言字符串操作函数 - strcpy、strcmp、strcat、反转、回文

    转自:C语言字符串操作函数 - strcpy.strcmp.strcat.反转.回文 C++常用库函数atoi,itoa,strcpy,strcmp的实现 作者:jcsu C语言字符串操作函数 1. ...

  2. php中常用的字符串查找函数strstr()、strpos()实例解释

    string strstr ( string $haystack , mixed $needle [, bool $before_needle = false ] ) 1.$haystack被查找的字 ...

  3. C/C++字符串查找函数

    C/C++ string库(string.h)提供了几个字符串查找函数,如下: memchr 在指定内存里定位给定字符 strchr 在指定字符串里定位给定字符 strcspn 返回在字符串str1里 ...

  4. Strsafe.h:更安全的C语言字符串处理函数

    原文出处:Strsafe.h: Safer String Handling in C 作者:Michael Howard 编译:王凌峰 在微软公司举行的Microsoft Windows Securi ...

  5. C/C++字符串查找函数 <转>

    C/C++ string库(string.h)提供了几个字符串查找函数,如下: memchr 在指定内存里定位给定字符 strchr 在指定字符串里定位给定字符 strcspn 返回在字符串str1里 ...

  6. C语言字符串操作函数 - strcpy、strcmp、strcat、反转、回文

    原文:http://www.cnblogs.com/JCSU/articles/1305401.html C语言字符串操作函数 1. 字符串反转 - strRev2. 字符串复制 - strcpy3. ...

  7. php字符串查找函数 php查找字符串中出现的次数函数substr_count,判断字符串中是否包含另一个字符串函数strpos

    php字符串查找函数 php查找字符串中出现的次数函数substr_count,判断字符串中是否包含另一个字符串函数strpossubstr_count($haystack, $needle [,$o ...

  8. C语言字符串操作函数整理

    整理C语言字符串相关的函数,以程序方式验证,以注释方式做说明. #include<stdio.h> #include<string.h> #include<stdlib. ...

  9. C语言字符串处理函数

    函数名: strcpy  功  能: 拷贝一个字符串到另一个  用  法: char *stpcpy(char *destin, char *source);  程序例:  #include < ...

随机推荐

  1. CURL的使用<发送与接收数据>

    $headers = array( "TYPE:xxxxooooo", "TOKEN:00000000" ); $data = array( 'data' =& ...

  2. jquery checkBox的问题

    在新版的jquery中选择ckeckbox最好使用prop方法,否则会出现一些问题.比如手动点击取消,再使用代码全选或者反选时候就不好使啦!!!

  3. c 递归函数浅析

    所谓递归,简而言之就是应用程序自身调用自身,以实现层次数据结构的查询和访问. 递归的使用可以使代码更简洁清晰,可读性更好(对于初学者到不见得),但由于递归需要系统堆栈,所以空间消耗要比非递归代码要大很 ...

  4. POJ 2411 压缩状态DP

    这个题目非常赞! 给定一个矩形,要求用1*2 的格子进行覆盖,有多少种覆盖方法呢? dp[i][j] 当状态为j,且第i行已经完全铺满的情况下的种类数有多少种?j中1表示占了,0表示没有被占. 很显然 ...

  5. UML include、generalization、extend、association

    1.别人的说法 转自:http://www.cnblogs.com/shinings/archive/2009/04/21/1440765.html 共性:都是从现有的用例中抽取出公共的那部分信息,作 ...

  6. 搭建Git Server

    windows上如何搭建Git Server   Git在版本控制方面,相比与SVN有更多的灵活性,对于开源的项目,我们可以托管到Github上面,非常方便,但是闭源的项目就会收取昂贵的费用.那么私有 ...

  7. linux grep、find 命令详解

    grep1.作用grep命令可以指定文件中搜索特定的内容,并将含有这些内容的行标准输出.grep全称是Global Regular Expression Print,表示全局正则表达式版本,它的使用权 ...

  8. sql之表连接和group by +组函数的分析

    1.首先我们来先看一个简单的例子: 有[Sales.Orders]订单表和[Sales.Customers]顾客表,表的机构如下 业务要求:筛选  来自“按时打算”国家的用户以及所下的订单数 sele ...

  9. ios 中定时器:NSTimer, CADisplayLink, GCD

    #import "ViewController.h" #import "RunloopViewController.h" @interface ViewCont ...

  10. hdu 4722 Good Numbers(规律题)

    http://acm.hdu.edu.cn/showproblem.php?pid=4722 [题意]: 找GoodNumbers一个数N,如果它每一个位数字之和可以整除10,那么它就是GoodNum ...