常用c函数收集

5 篇文章 0 订阅

1 strstr:      

 The strstr() function finds the first occurrence of the substring needle in the string haystack.  The terminating null bytes ('\0') are not compared.

       The strcasestr() function is like strstr(), but ignores the case of both arguments.

在串中查找指定字符串的第一次出现 


2 strtok:

      The  strtok()  function  breaks a string into a sequence of zero or more nonempty tokens.  On the first call to strtok() the string to be parsed should be specified in
       str.  In each subsequent call that should parse the same string, str must be NULL.

用于在一个字符串中遍历查找子串

例子:

#include <string .h>
int main(int argc, char* argv[])
{
    char *p=NULL;
        char str[] ="123,4567,8,9,01,44";
        const char * split = ","; 
    p = strtok (str,split); 
    while(p!=NULL) { 
    printf ("%s %d\n",p,strlen(p)); 
    p = strtok(NULL,split); 
    } 
    return 0;
}


3 setlocale:
设置程序执行的编码环境,会影响字符串长度的计算(比如中文字符串的长度)




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值