zoukankan      html  css  js  c++  java
  • 写的split带改进

    #include <stdio.h>
    #include <ctype.h>
    char** split(int* out,char in[])
    {
        char *p1,*p2;
        p1 = p2 = in;
        int count=1;
        while((*p2)!='\0')
        {
            if((*p2)==',')
            {
                count++;
            }
            p2++;
        }
        *out=count;
        char** result=(char**)malloc(count*sizeof(char *));
       
        count=0;
        for(p2=p1;(*p2)!='\0',(*p1)!='\0';p2++)
        {
            if((*p2)==',')
            {
                int r=(p2-p1);
                if(r>0)
                {
                    char* pp=(char*)malloc((r+1)*sizeof(char));
                    strncpy(pp,p1,r);
                    *(pp+r+1)='\0';
                    *(result+count)=pp;
                    count++;
                    p1=p2+1;
                }
               
            }
        }
       
       
        return result;
       
    }


    int main()
    {

        char b[]="ab";
        int out=0;
        char** r=split(&out,b);
        printf("%s\n",*r);
        //printf("%s\n",*(r+1));
        printf("%d\n",out);
        return 0;
    }

  • 相关阅读:
    Codeforces Round #249 (Div. 2) D. Special Grid 枚举
    图论二
    C语言中的atan和atan2(转)
    BestCoder Round #79 (div.2)
    数学
    LCA
    二分图
    动态规划
    线段树
    树状数组
  • 原文地址:https://www.cnblogs.com/lexus/p/3033434.html
Copyright © 2011-2022 走看看