?
Solved

NT4 VisualStudio97 -- strtok flaky ?

Posted on 1998-10-07
5
Medium Priority
?
256 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 100 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

Technology Partners: 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!

Question has a verified solution.

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

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…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.

770 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