字符函数2

今天主要是承接昨天的字符函数学习

加注头文件  #include<string.h>

一般带n的就是需要限制长度

拼接函数 strcat(a,b)

 (a,b)    b接在a后面 

    char src[10] = "hello    ";
   char cc[30] = "xyh    ";
   strcat(src,cc);//  
   printf("%s\n",src);
    strncat(cc,src,5);        //将src前?个加入cc 
    printf("%s\n",cc);

  比较函数 strcmp

     比较两个函数大小?前比后,大非零,小为负
 

    char s[10] = "happy";
   char a[10] = "xianxian";
   int ret = strcmp(s,a);
    printf("%d\n",ret);
   
   int ret  =    strncmp(s,a,1);
   printf("%d\n",ret);

    切割字符串的函数strtok
        分割出每个单词

    char s[20] = "this is main";
    char *ps =    NULL;
    ps = strtok(s," ");
    puts(ps);
   while(ps!=NULL){
       ps = strtok(NULL," ");
      printf("%s\n",ps);

    查字母第一次出现的位置 strchr

//    char s[20] = "hello    world";
//    char a ='o';
//    char *p = strchr(s,a);//找字母第一次出现的位置 
//    printf("%s\n",p);
//    printf("%p\n",s);
//    printf("%p\n",p);

    依次检索字符串 strpbrk

//    char s[20] = "hello    world";
//    char ch[3] = "orl";
//    int a = 111;
//    char *p;
//    p = strpbrk(s,ch);
//    printf("%s\n",p);
//    printf("%p\n",p);

  确定字符串首次出现的位置 strstr
 

//    char s[20] = "hello    world";
//    char ch[1000] = "llo";
//    int a = 111;
//    char *p;
//    p = strstr(s,ch);
//    printf("%s\n",p);
//    printf("%p\n",p);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值