• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
我是张洪铭我是熊博士
时光静好,与君同;细水长流,与君语
博客园    首页    新随笔    联系   管理    订阅  订阅

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\n",p);  
    18.     }  
    19.     else  
    20.     {  
    21.         printf("Not Found!\n");  
    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\n",p);  
    38.     if (p==NULL)  
    39.     {  
    40.         printf("Not Found!\n");  
    41.     }  
    42.     p=strstr(p,"one");  
    43.     printf("%s\n",p);  
    44.     if (p==NULL)  
    45.     {  
    46.         printf("Not Found!\n");  
    47.     }  
    48.     p+=strlen("one");  
    49.     printf("%s\n",p);  
    50.   
    51.     getch();  
    52.     return 0;  
    53. }  
    54. #endif 

 

posted @ 2017-10-13 08:08  我是张洪铭我是熊博士  阅读(555)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3