C语言函数

编辑

包含文件:string.h
函数名: strstr
函数原型:
     extern char *strstr(char *str1, const char *str2);
语法:
* strstr(str1,str2)
str1: 被查找目标 string expression to search.
str2: 要查找对象 The string expression to find.
返回值:若str2是str1的子串,则返回str2在str1的首次出现的地址;如果str2不是str1的子串,则返回NULL。

应用举例

#include <syslib.h>
#include <string.h>
main()
{
    char *s="GoldenGlobalView";
    char *l="lob";
    char *p;
    clrscr();
    p=strstr(s,l);
    if(p)
        printf("%s",p);
    else
        printf("NotFound!");
    getchar();
    return0;
}
//功能:从字串” string1 onexxx string2 oneyyy”中寻找”yyy”
(假设xxx和yyy都是一个未知的字串)
char *s=”string1onexxxstring2oneyyy”;
char *p;
p=strstr(s,”yyy”);
if(p!=NULL)
    printf(“%s”,p);
else
    printf("notfound\n");
说明:如果直接写语句p=strstr(s,”one”),找到的是onexxxstring2oneyyy
char *mystrstr(char*s1,char*s2)
{
    if(*s1==0)
    {
        if(*s2)
            return (char*)NULL;
        return (char*)s1;
    }
    while(*s1)
    {
        int i=0;
        while(1)
        {
            if(s2[i]==0)
                return s1;
            if(s2[i]!=s1[i])
                break;
            i++;
        }
        s1++;
    }
    return (char*)NULL;
}

strstr函数的用法的更多相关文章

  1. strstr 函数用法

    strstr 编辑 strstr(str1,str2) 函数用于判断字符串str2是否是str1的子串.如果是,则该函数返回str2在str1中首次出现的地址:否则,返回NULL. C语言函数 编辑 ...

  2. PHP strstr() 函数

    实例 查找 "world" 在 "Hello world!" 中是否存在,如果是,返回该字符串及后面剩余部分: <?php echo strstr(&qu ...

  3. 有关日期的函数操作用法总结,to_date(),trunc(),add_months();

    相关知识链接: Oracle trunc()函数的用法 oracle add_months函数 Oracle日期格式转换,tochar(),todate() №2:取得当前日期是一个星期中的第几天,注 ...

  4. Oracle to_date()函数的用法

    Oracle to_date()函数的用法 to_date()是Oracle数据库函数的代表函数之一,下文对Oracle to_date()函数的几种用法作了详细的介绍说明,供您参考学习. 在Orac ...

  5. js中bind、call、apply函数的用法

    最近一直在用 js 写游戏服务器,我也接触 js 时间不长,大学的时候用 js 做过一个 H3C 的 web的项目,然后在腾讯实习的时候用 js 写过一些奇怪的程序,自己也用 js 写过几个的网站.但 ...

  6. strstr 函数的实现

    strstr函数:返回主串中子字符串的位置后的所有字符. #include <stdio.h> const char *my_strstr(const char *str, const c ...

  7. Oracle trunc()函数的用法

    Oracle trunc()函数的用法 /**************日期********************/1.select trunc(sysdate) from dual --2013-0 ...

  8. freemarker内置函数和用法

    原文链接:http://www.iteye.com/topic/908500 在我们应用Freemarker 过程中,经常会操作例如字符串,数字,集合等,却不清楚Freemrker 有没有类似于Jav ...

  9. matlab中patch函数的用法

    http://blog.sina.com.cn/s/blog_707b64550100z1nz.html matlab中patch函数的用法——emily (2011-11-18 17:20:33) ...

随机推荐

  1. JS定义函数的两种方式:函数声明和函数表达式

    函数声明 关于函数声明的方式,它的一个重要的特性就是函数声明提升(function declaration hoisting),意思是在执行代码之前会先读取函数声明.这就意味着可以把函数声明放在调用它 ...

  2. AC 设置DMZ口上网

  3. git和nginx安装

    原始地址: https://www.zybuluo.com/freeethy/note/192109 git安装 设置git的username和email (注册gitlab的账号密码) $$ git ...

  4. js的原型模式

    以下内容来自<JavaScript高级程序设计>第三版 我们创建的每个函数都有一个prototype(原型)属性,这个属性是一个指针,指向一个对象,而这个对象的用途是包含可以由特定类型的所 ...

  5. windows服务器的DDOS防御,

    抵御 SYN 攻击 SYN 攻击利用了 TCP/IP 连接建立机制中的安全漏洞.要实施 SYN 洪水攻击,攻击者会使用程序发送大量 TCP SYN 请求来填满服务器上的挂起连接队列.这会禁止其他用户建 ...

  6. 配合crond服务实现自定义周期备份MySQL数据库(使用innobackupex进行备份)

    备份 新建一个脚本/root/backup.py,内容如下: #!/usr/bin/env python# -*- coding: utf-8 -*- ''' 脚本作者:昨夜星辰 脚本作用:配合cro ...

  7. 解决错误 Cannot await in the body of a catch clause

      解决错误 Cannot await in the body of a catch clause   static async Task f() { ExceptionDispatchInfo ca ...

  8. 生成CIL的问题

    private void testILMethod() { InventCountPlanLine planLine; ; update_recordSet planLine setting Coun ...

  9. Patching Array

    引用原文:http://blog.csdn.net/murmured/article/details/50596403 但感觉原作者的解释中存在一些错误,这里加了一些自己的理解 Given a sor ...

  10. linux 学习10 shell 基础

    10.1 Shell概述 .Shell是什么 Shell是一个命令行解释器,它为用户提供了一个向Linux内核发送请求以便运行程序的界面系统级程序,用户可以用Shell来启动.挂起.停止甚至是编写一 ...