Playing with strings

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Mar 2005
Posts: 64
Reputation: atrusmre is an unknown quantity at this point 
Solved Threads: 0
atrusmre's Avatar
atrusmre atrusmre is offline Offline
Junior Poster in Training

Playing with strings

 
0
  #1
Oct 26th, 2005
I am working on a project that requires me to recive data from a network application. After I recive the data I'm suppose to break it up. Now I know of a way to sorta do that by using "tokens" and strtok (if you don't know strok breaks up a string by delminating character i.e. \n ). My problem is that I need to do it twice. Once for "\n" and once for "\t", but my program crashes when I use strtok a second time. For example:
  1. tokenPtr = strtok (m_pBuf , "\n");
  2. while ( tokenPtr != NULL )
  3. {
  4. temp[i] = tokenPtr;
  5. tokenPtr = strtok(NULL, "\n");
  6. i++;
  7. }
This works, but doesn't give to resluts needed. I need to break it further up, however:
  1. tokenPtr = strtok (m_pBuf , "\n");
  2. while ( tokenPtr != NULL )
  3. {
  4. temp[i] = tokenPtr;
  5. tokenPtr = strtok(NULL, "\n");
  6. i++;
  7. }
  8. while ( count <= i )
  9. {
  10. tokenPtr = strtok (temp[count] , "\t");
  11. while ( tokenPtr != NULL )
  12. {
  13. temp2[j] = tokenPtr;
  14. tokenPtr = strtok(NULL, "\t");
  15. j++;
  16. }
  17. count++;
  18. tokenPtr = "";
  19. }
crashes the program.
Any ideas on how to work this out?
Reply With Quote Quick reply to this message  
Join Date: Oct 2005
Posts: 17
Reputation: invinate is an unknown quantity at this point 
Solved Threads: 0
invinate invinate is offline Offline
Newbie Poster

Re: Playing with strings

 
0
  #2
Oct 26th, 2005
why can't you just strtok(str, "\t\n") ?
Reply With Quote Quick reply to this message  
Join Date: Mar 2005
Posts: 64
Reputation: atrusmre is an unknown quantity at this point 
Solved Threads: 0
atrusmre's Avatar
atrusmre atrusmre is offline Offline
Junior Poster in Training

Re: Playing with strings

 
0
  #3
Oct 26th, 2005
WOW!!! Thank you!!! That worked exactly like I wanted!! Thank you so much. (In answer to your question, I didn't know I could do that and make it work right. It doesn't seem like it would, but it does!) Thank you again!
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C Forum
Thread Tools Search this Thread



Tag cloud for C
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC