Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!mailrus!cornell!rochester!uhura.cc.rochester.edu!ur-valhalla!micropen!steve From: steve@micropen (Steven J. Owens) Newsgroups: comp.unix.questions Subject: Re: ????? HELP!!! what is wring with this code? ??????? Summary: A few possibilities... Message-ID: <560@micropen> Date: 12 Oct 88 21:02:19 GMT References: <456@mrsvr.UUCP> Organization: Micropen Dirent Writing Systems, Pittsford, NY Lines: 43 In article <456@mrsvr.UUCP>, ssa@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