Solved

NT4 VisualStudio97 -- strtok flaky ?

Posted on 1998-10-07
5
247 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
Comment Utility
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
Comment Utility
Great. Thanks for comments. I think I need bounds checker prog
0
 
LVL 32

Accepted Solution

by:
jhance earned 50 total points
Comment Utility
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
Comment Utility
Thanks, jhance
I would like the points to go to Answers2000's comment
but here they are.
0
 
LVL 8

Expert Comment

by:Answers2000
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

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…
Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.

771 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now