User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 422,558 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,610 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums

how do i parse a custom delimited file

Join Date: Apr 2007
Posts: 10
Reputation: Lance Wassing is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
Lance Wassing Lance Wassing is offline Offline
Newbie Poster

Re: how do i parse a custom delimited file

  #5  
Apr 2nd, 2007
Well guys,

I have tried the obvious.

I think I may be doing something a little wrong, or the strtok(str, delims) function is not going to suffice.

The test file i made looks like this
BLUE | GREEN
RED | ORANGE
PURPLE | PINK
YELLOW | BLACK

and the code looks like this:
  1. //Open the file, and copy the file into the buffer
  2. FILE * f;
  3. char * buffer;
  4. long size;
  5. f = fopen("test.txt","rt+");
  6. if( f == NULL) exit(1);
  7.  
  8. fseek(f,0,SEEK_END);
  9. size = ftell(f);
  10. rewind(f);
  11.  
  12. buffer = (char*) malloc(size);
  13. if(buffer == NULL) exit(2);
  14.  
  15. fread(buffer, 1, size, f);
  16. fclose(f);
  17.  
  18. //Now we're going to parse the file
  19. char * temp;
  20. String * Array = new String[5];
  21. temp = strtok(buffer,"|");
  22. RichEdit1->Lines->Add(temp);

unfortunately, the output in the RichEdit1 Box, is BLUE. Does anyone know why? or how i can fix this. If so please... PLEASE... respond. Im a bit stumped here.

Thanks,
Lance
Last edited by WaltP : Apr 2nd, 2007 at 9:02 pm. Reason: Fixed CODE tags -- doesn't anyone know what the PREVIEW button is for???
Reply With Quote  
All times are GMT -4. The time now is 1:11 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC