Get Paid for Working on Projects Matching Your Expertise at Go4Expert's Jobs Board
Go4Expert
Go4Expert RSS Feed

Go Back   Programming and SEO Forum >  Go4Expert > Queries and Discussion > Programming > C-C++

Reply  Copy HTML to Clipboard  Copy BBCode to Clipboard  | More
 
Bookmarks Thread Tools Search this Thread Display Modes
Old 04-21-2008, 05:46 PM   #1
Newbie Member
 
Join Date: Apr 2008
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
dusoo is on a distinguished road

string changing - problem


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 shabbir; 04-21-2008 at 06:05 PM.. Reason: Code block
dusoo is offline   Reply With Quote
Reply  Copy HTML to Clipboard  Copy BBCode to Clipboard  | More


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes
Bookmarks

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

 

All times are GMT +5.5. The time now is 02:04 AM.