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 

 

原文链接: https://www.cnblogs.com/azbane/p/7659227.html

欢迎关注

微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍;

也有高质量的技术群,里面有嵌入式、搜广推等BAT大佬

    char *strstr(const char *str1, const char *str2);

原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/399142

非原创文章文中已经注明原地址,如有侵权,联系删除

关注公众号【高性能架构探索】,第一时间获取最新文章

转载文章受原作者版权保护。转载请注明原作者出处!

(0)
上一篇 2023年4月12日 上午9:59
下一篇 2023年4月12日 上午9:59

相关推荐