Solved

NT4 VisualStudio97 -- strtok flaky ?

Posted on 1998-10-07
5
251 Views
Last Modified: 2010-04-15
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
Comment
Question by:mbarron
  • 2
  • 2
5 Comments
 
LVL 8

Expert Comment

by:Answers2000
ID: 1253407
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
 

Author Comment

by:mbarron
ID: 1253408
Great. Thanks for comments. I think I need bounds checker prog
0
 
LVL 32

Accepted Solution

by:
jhance earned 50 total points
ID: 1253409
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
 

Author Comment

by:mbarron
ID: 1253410
Thanks, jhance
I would like the points to go to Answers2000's comment
but here they are.
0
 
LVL 8

Expert Comment

by:Answers2000
ID: 1253411
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

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

822 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question