zoukankan      html  css  js  c++  java
  • char *strstr(const char *str1, const char *str2);

    【FROM MSDN && 百科】

    原型:char *strstr(const char *str1, const char *str2);

    #include<string.h>

    找出str2字符串在str1字符串中第一次出现的位置(不包括str2的串结束符)。返回该位置的指针,如找不到,返回空指针。

     

    Returns a pointer to the first occurrence of strSearch in str, or NULL if strSearch does not appear in str. If strSearch points to a string of zero length, the function returns str.

    DEMO: mystrstr

      1. //#define FIRST_DEMO  
      2. #define SECOND_DEMO  
      3.   
      4. #ifdef FIRST_DEMO  
      5. #include <stdio.h>  
      6. #include <conio.h>  
      7. #include <string.h>  
      8. int main(void)  
      9. {  
      10.     char *s="Golden Global View";  
      11.     char *l="lob";  
      12.     char *p;  
      13.     system("cls");  
      14.     p=strstr(s,l);  
      15.     if (p!=NULL)  
      16.     {  
      17.         printf("%s ",p);  
      18.     }  
      19.     else  
      20.     {  
      21.         printf("Not Found! ");  
      22.     }  
      23.   
      24.     getch();  
      25.     return 0;  
      26. }  
      27. #elif defined SECOND_DEMO  
      28. /*从字串” string1 onexxx string2 oneyyy”中寻找”yyy”*/  
      29. #include <stdio.h>  
      30. #include <conio.h>  
      31. #include <string.h>  
      32. int main(void)  
      33. {  
      34.     char *s="string1 onexxx string2 oneyyy";  
      35.     char *p;  
      36.     p=strstr(s,"string2");  
      37.     printf("%s ",p);  
      38.     if (p==NULL)  
      39.     {  
      40.         printf("Not Found! ");  
      41.     }  
      42.     p=strstr(p,"one");  
      43.     printf("%s ",p);  
      44.     if (p==NULL)  
      45.     {  
      46.         printf("Not Found! ");  
      47.     }  
      48.     p+=strlen("one");  
      49.     printf("%s ",p);  
      50.   
      51.     getch();  
      52.     return 0;  
      53. }  
      54. #endif 
  • 相关阅读:
    第五章
    第四章
    第三章
    第二章
    第一章
    configparser-xml-subprocess-shutil
    sys,os,模块-正则表达式
    %----format 格式化字符串---- 生成器---- 迭代器
    python 内置函数
    python 内置函数!
  • 原文地址:https://www.cnblogs.com/azbane/p/7659227.html
Copyright © 2011-2022 走看看