zoukankan      html  css  js  c++  java
  • str函数

    strstr

    #include<stdio.h>
    #include<string.h>
    
    int main( int argc, char *argv[] )
    {
        int rc=0;
        char *str = "http://www.bbb.com";
        char *p = strstr(str,"www");             结果:www.bbb.com
    char *p1 = strchr(str, '/'); // 结果://www.bbb.com printf(
    "%s p:%s %u ", str,p, __LINE__); return rc; }

    结果:

    $ gcc -o str.o str.c
    $ ./str.o
    $ http://www.bbb.com p:www.bbb.com 9

    字符串后向匹配

    int main( int argc, char *argv[] )
    {
        int rc=0;
        char *visit = "http://www.bbb.com/eee";
        char *p;
        char v_http[32],url[32];
        if(!strncmp(visit,"http://",7)){
           strcpy (v_http, visit+7);
           p = strchr(v_http, '/');
           if(p){
             strncpy (url, v_http, p - v_http);
           }
           printf("1 url %s p:%s v_http %s %lu
    ", url,p, v_http,p - visit);
    
        }else{
           strncpy (v_http, visit+4, p - visit);
           printf("2 visit %s p:%s str1 %s %lu
    ", visit,p, v_http,p - visit);
        }
        char *list = "bbb.com";
        rc = strncmp(list, url, strlen(list));
        char *p1 = strstr(url,list);
        printf("3 visit %s list %s rc %d %s
    ", visit,list,rc,p1);
        return rc;
    }
    
    # gcc -o str2.o str2.c
    # ./str2.o
    1 url www.bbb.com p:/eee v_http www.bbb.com/eee 140731426069911
    3 visit http://www.bbb.com/eee list bbb.com rc -21 bbb.com
  • 相关阅读:
    NOJ 1116 哈罗哈的大披萨 【淡蓝】 状态压缩DP
    优先队列原理与实现【转】
    testC-I
    济南NOIP冬令营 选拔(select)
    P4747 D’s problem(d)
    P4746 C’s problem(c)
    P4745 B’s problem(b)
    P4744 A’s problem(a)
    [bzoj] 1004: [HNOI2008]Cards
    NOIP2013 表达式求值
  • 原文地址:https://www.cnblogs.com/abc36725612/p/11593421.html
Copyright © 2011-2022 走看看