zoukankan      html  css  js  c++  java
  • strstr函数

    函数原型:extern char *strstr(char *haystack, char *needle)

    参数说明:haystack为一个源字符串的指针,needle为一个目的字符串的指针。
            
    所在库名:#include <string.h>
      
    函数功能:从字符串haystack中寻找needle第一次出现的位置,但是该函数不比较结束符NULL。
      
    返回说明:返回指向第一次出现needle位置的指针,如果没找到则返回NULL。

    其它说明:暂时无。

    实例:

    #include<string.h>
    #include
    <stdio.h>
    int main()
    {
        
    char *haystack="Hello,I am sky2098,I liking programing!";
        
    char *needle="gram";
        
    char *temp;

        temp
    =strstr(haystack,needle);
        
    if(temp!=NULL)
        
    {
            printf(
    "%s ",temp);
        }

        
    else
        
    {
            printf(
    "Can not find [ %s ] from [ %s] ! ",needle,haystack);
        }

        
    return 0;
    }

    在VC++ 6.0编译运行:


      
    当然,如果我们没有从源字符串中查找到要匹配的字符串,例如查找gramk会提示:

    Can not find [ gramk ] from [ Hello,I am sky2098,I liking programing!] !

  • 相关阅读:
    ceph部署与问题
    openstack常见问题汇总
    css
    html
    zookeeper
    ZAB协议
    快速排序
    Servlet梳理
    tomcat性能优化梳理
    tomcat梳理
  • 原文地址:https://www.cnblogs.com/lgh1992314/p/5835378.html
Copyright © 2011-2022 走看看