C Raise _day03_ Two auxiliary pointer variable dig string (reinforcement 3)

Source: Internet
Author: User

#define_crt_secure_no_warnings#include<stdlib.h>#include<string.h>#include<stdio.h>//the third memory model for two auxiliary pointer variables to dig a string//pointers do function argumentsintSpitString4 (Char*BUF1,CharCCharMYP3,int*count)//**pp Level two pointer input{    Char*p=null, *ptmp =NULL; intTmpcount =0; intLen; Char**myp=NULL; //1 P and ptmp initializationp =buf1; Ptmp=buf1; //the first time to find Count     Do    {        //2 Retrieving a position that matches the condition P moves back to form a difference digging stringp =STRCHR (P, c); if(P! =NULL) {            if(P-ptmp >0) {Tmpcount++; //3 re-enable p and ptmp to reach the next search conditionptmp = p = p +1; }        }        Else        {             Break; }    }  while(*p!=' /'); *count =Tmpcount; //accurately allocate memory based on how many rowsMyp= (Char**)malloc(Tmpcount *sizeof(Char*)); if(myp==NULL) {        return-1; }      /////////////////////////////////////////////////////////Tmpcount=0; //1 P and ptmp initializationp =buf1; Ptmp=buf1;  Do    {        //2 Retrieving a position that matches the condition P moves back to form a difference digging stringp =STRCHR (P, c); if(P! =NULL) {            if(P-ptmp >0) {len=p-ptmp+1; Myp[tmpcount]=(Char*)malloc(Len *sizeof(Char)); if(myp==NULL) {                    return-1; } strncpy (Myp[tmpcount],ptmp,p-ptmp); Myp[tmpcount][p-ptmp]=' /'; Tmpcount++; //3 re-enable p and ptmp to reach the next search conditionptmp = p = p +1; }        }        Else        {             Break; }    }  while(*p!=' /'); //*count = Tmpcount;*MYP3 = MYP;//MYP3 is a value of level two pointer address    return 0;}intMain () {inti; intret=0 ; Char*p1="ABCDEF,AAA,EEEEE,FFFFFF,A3A3A3,"; Chartmp=','; Char**p=NULL; intncount; RET=spitstring4 (p1,tmp,&p,&ncount); if(ret!=0) {printf ("Fun spiltstring () err:%d \ n", ret); returnret; }     for(i=0; i<ncount;i++) {printf ("%s \ n", P[i]); }     for(i=0; i<ncount;i++)    {         Free(P[i]); }     Free(P); printf ("%d \ n", ncount); printf ("hello...\n"); System ("Pause");}

C Raise _day03_ Two auxiliary pointer variable dig string (reinforcement 3)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.