1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

string changing - problem

Discussion in 'C' started by dusoo, Apr 21, 2008.

  1. dusoo

    dusoo Banned

    Joined:
    Apr 21, 2008
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Hello everyone.
    Im playing with one parser that is not working.
    It's failing with segment.error, and I could not fix it, since im not good at all in c :(.
    I think the issue is in one place, where im trying to change one string to other one. It's always failing on third step - ending with that segm.error.
    Im calling fillcd, where cid2cid "function" is used to modify the buf string.
    After third succesfully changed string it fails…Isnt there a memory problem?

    buf: 3000/000/00/MOY,3000/000/00/MAX,3000/000/00/CUM, 3000/000/00/ECH,3004/000/00/CUM,3004/000/00/ECH,3004/000/00/MOY, 3004/000/00/MAX,3004/001/00/CUM,3004/001/00/ECH,3004/001/00/MOY, 3004/001/00/MAX, 3008/000/00/CUM,3008/000/00/ECH,3008/000/00/MOY

    Output in cd variable should be like: MOY_3000_000_00,MAX_3000_000_00,CUM_3000_000_00, ….

    Thanks for any ideas !

    Script:

    ...
    Code:
    char *cid2cid(char *s){
      static char tmp[20];
    
        printf("subor:%s\n",s);
        fflush(stdout); 
          
      strcpy(tmp, s);
      s[0]=tmp[12]; 
      s[1]=tmp[13];
      s[2]=tmp[14];
      s[3]='_';
      s[4]=tmp[0];
      s[5]=tmp[1];
      s[6]=tmp[2];
      s[7]=tmp[3];
      s[8]='_';
      s[9]=tmp[5];
      s[10]=tmp[6];
      s[11]=tmp[7];
      s[12]='_';
      s[13]=tmp[9];
      s[14]=tmp[10];
      s[15]='\0';
      return s;
    }
    
    int fillcd( char *buf, char *cd[], FILE *f ) {
      char *p;
      int i;
    //my part start
      printf("subor:%s\n",buf);
      fflush(stdout);     
    //my part end    
      cd[0]=cid2cid(strdup(strtok(buf,",")));
      i=1;
        printf("subor:%s\n",cd[0]);
      while ( (p=strtok(NULL, ",")) != NULL ) cd[i++]=strdup(cid2cid(p));
      cd[i]=strdup("FINITO");
      return i;
    }
    


    char buf[1000], classn[100], *procstr[100], *cd[200];
    counters=fillcd(inbuf,cd, fout);

    Thanks for any ideas !
     
    Last edited by a moderator: Apr 21, 2008

Share This Page