????? HELP!!! what is wring with this code? ???????
Steven J. Owens
steve at micropen
Thu Oct 13 07:02:19 AEST 1988
In article <456 at mrsvr.UUCP>, ssa at mrsvr.UUCP (6607) writes:
>
> For the life of me I can't figure out what is wrong with the following
> code!!!! It is supposed to parse words from a string in which words
> are delimited by blanks or tabs, and print one word a line. Simple
> right? well not quite.
Well, let's take a look at the line:
> while((tokptr=strtok(strptr," \t")) != NULL ){
> So, what is wrong???
First of all, as normal practice I try not to #define
NULL, as many systems define this to be a char * anyways. If
you'd like, you could make the line read:
while((tokptr=strtok(strptr," \t")) != (char *)NULL ){
As this is good, portable coding practice.
This is kind of a small point, but is strtok() defined
to be char * ? Yeah, I know. The manual says it is, but that doesn't
necessarily mean it is. Where I work, it's been our practice
to define these ourselves as well whenever possible. It is simply
good, portable practice to make sure things are what we think they
are.
Your setting the variable strptr to buf, while appearing
harmless( and probably is ) would make me wince. It is simply
unnecessary to do that, but that is my personal preference.
SJO
--
Steve Owens @ Micropen, Inc.
Pittsford, N.Y. 14534
...!{ames|harvard|rutgers|topaz|...}!rochester!ur-valhala!micropen!steve
More information about the Comp.unix.questions
mailing list