• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 261
  • Last Modified:

NT4 VisualStudio97 -- strtok flaky ?

Have
char *pC;
 // where  pData=="123" // no comma present
  pC=strtok(pData,",");
This call cause an "unhandled expection. 0xC000005"
Shouldn't it return NULL ?
Does this mean that my earlier code
has hosed strtok?
What do I do?
0
mbarron
Asked:
mbarron
  • 2
  • 2
1 Solution
 
Answers2000Commented:
I've never had problems with strtok.

In general the code should return NULL, except in one case

(begin quote)
Warning Each of these functions uses a static variable for parsing the string into tokens. If multiple or simultaneous calls are made to the same function, a high potential for data corruption and inaccurate results exists. Therefore, do not attempt to call the same function simultaneously for different strings and be aware of calling one of these function from within a loop where another routine may be called that uses the same function. However, calling this function simultaneously from multiple threads does not have undesirable effects.
(end quote)

Things to check
1. pData is NUL terminated
2. Other calls to strtok (single buffer problem - see the quote above)

If you still have problems after doing this checking, try using strchr to find delimiters.  If this doesn't work either (strchr doesn't rely on a single buffer incidentally), then you've probably nuked the runtime library/environment with some previous code going haywire.

0xC0000005 is an access violation (meaning strtok is reading somewhere it shouldn't)m which is why it could be #1 or #2 above
0
 
mbarronAuthor Commented:
Great. Thanks for comments. I think I need bounds checker prog
0
 
jhanceCommented:
You're not using strtok correctly.  You need to call it the FIRST time like you are calling it to initialize the function.  Then you need to call it again with a NULL in the first argument to actually find the token.  In your case, are you calling strtok wrong earlier in the program and getting it confused????
0
 
mbarronAuthor Commented:
Thanks, jhance
I would like the points to go to Answers2000's comment
but here they are.
0
 
Answers2000Commented:
mbarron, it's ok

next time if you want to give pts to somebody who made a comment,
1. then reject the current answer (if there is one)
2 and post a comment requesting who-ever to post a dummy answer.

See ya
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now