Link to home
Start Free TrialLog in
Avatar of mbarron
mbarron

asked on

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?
Avatar of Answers2000
Answers2000

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
Avatar of mbarron

ASKER

Great. Thanks for comments. I think I need bounds checker prog
ASKER CERTIFIED SOLUTION
Avatar of jhance
jhance

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mbarron

ASKER

Thanks, jhance
I would like the points to go to Answers2000's comment
but here they are.
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