分享

strstr和strtok函数

 十指紧ㄣ扣 2010-08-02

 
char *strtok(char *s, char *delim);
 功能:分解字符串为一组字符串。s为要分解的字符串,delim为分隔符字符串。
 说明:首次调用时,s指向要分解的字符串,之后再次调用要把s设成NULL。strtok在s中查找包含在delim中的字符并用'\0'来替换,直到找遍
                整个字符串。
 返回值:从s开头开始的一个个被分割的串。当没有被分割的串时则返回NULL。所有delim中包含的字符都会被滤掉,并将被滤掉的地方设为一处
                分割的节点。

#include <stdio.h>
#include 
<string.h>
int main(void)

output:
wo_
shi_
yi_
ge_
xuesheng_
Press any key to continue
 
 

char *strstr (const char *s1, const char *s2);
说明:返回一个指针,它指向s1中第一次出现s2字符序列(不包括'\0'字符)的位置,没有匹配的则返回NULL
#include <stdio.h>
#include 
<string.h> 
 
int main(void)
{
    
char *haystack="aaa||a||bbb||c||ee||";
    
char *needle="||";
    
char *buf = strstr( haystack, needle);
    
if(buf != NULL)
        printf( 
"%s\n", buf);
    
return 0;
}

output:
||a||bbb||c||ee||
Press any key to continue

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多