home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!olivea!bu.edu!news.tufts.edu!news.tufts.edu!gowen
- From: gowen@jade.tufts.edu (G. Lee Owen)
- Newsgroups: comp.lang.c
- Subject: Re: Multiple &'s in an if statement
- Message-ID: <GOWEN.92Nov23130506@jade.tufts.edu>
- Date: 23 Nov 92 18:05:36 GMT
- Sender: news@news.tufts.edu (USENET News System)
- Distribution: na
- Organization: Tufts University - Medford, MA
- Lines: 34
-
-
-
- Seen on 23-Nov-92, From: bcochell@ws14.ips.iacd.honeywell.com (Bill Cochell)
- > Can anyone explain why this works correctly (That is, it checks to see that
- > the last 5 characters of name are all digits and that it is null terminated):
- > if ( isdigit(name[strlen(path)]) &
- > /* ......... */
- > isdigit(name[(strlen(path) + 4)]) )
- > if ( iscntrl(name[(strlen(path) + 5)]) ) {
- > printf("%s\n",name);
- > }
- >While the following does not?:
- > if ( isdigit(name[strlen(path)]) &
- > /* ....... */
- > isdigit(name[(strlen(path) + 4)]) &
- > (name[(strlen(path) + 5)] == NULL ) ) {
- > printf("%s\n",name);
- > }
- > Why do I have to check for NULL with a separate if statement?
- Well, I suspect that the use of bitwise AND operator & instead
- of the logical AND operator && is at fault here. Bitwise ANDing will
- often give you the same result as logical ANDing, but not always. Try
- replacing the &'s with &&'s and see what happens.
-
- > Any opinions will be appreciated
- ^^^^^^^^
- Good, because without more code I wasn't really able to test
- my guess. Standard nontested code disclaimers apply.
-
-
- --
- --Greg Owen
- gowen@forte.cs.tufts.edu, gowen@jade.tufts.edu
- "C Spot. C Spot run. C Spot run without a core dump! Run, Spot, Run!"
-