home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / c / 17046 < prev    next >
Encoding:
Internet Message Format  |  1992-11-23  |  1.6 KB

  1. Path: sparky!uunet!olivea!bu.edu!news.tufts.edu!news.tufts.edu!gowen
  2. From: gowen@jade.tufts.edu (G. Lee Owen)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Multiple &'s in an if statement
  5. Message-ID: <GOWEN.92Nov23130506@jade.tufts.edu>
  6. Date: 23 Nov 92 18:05:36 GMT
  7. Sender: news@news.tufts.edu (USENET News System)
  8. Distribution: na
  9. Organization: Tufts University - Medford, MA
  10. Lines: 34
  11.  
  12.  
  13.  
  14. Seen on 23-Nov-92, From: bcochell@ws14.ips.iacd.honeywell.com (Bill Cochell)
  15. > Can anyone explain why this works correctly (That is, it checks to see that
  16. > the last 5 characters of name are all digits and that it is null terminated):
  17. >   if ( isdigit(name[strlen(path)]) &
  18. >             /* ......... */
  19. >        isdigit(name[(strlen(path) + 4)]) )
  20. >      if ( iscntrl(name[(strlen(path) + 5)]) ) {
  21. >         printf("%s\n",name);
  22. >      }
  23. >While the following does not?:
  24. >   if ( isdigit(name[strlen(path)]) &
  25. >           /* ....... */
  26. >        isdigit(name[(strlen(path) + 4)]) &
  27. >        (name[(strlen(path) + 5)] == NULL ) ) {
  28. >      printf("%s\n",name);
  29. >   }
  30. > Why do I have to check for NULL with a separate if statement?
  31.     Well, I suspect that the use of bitwise AND operator & instead
  32. of the logical AND operator && is at fault here.  Bitwise ANDing will
  33. often give you the same result as logical ANDing, but not always.  Try
  34. replacing the &'s with &&'s and see what happens.
  35.  
  36. > Any opinions will be appreciated
  37.       ^^^^^^^^
  38.     Good, because without more code I wasn't really able to test
  39. my guess.  Standard nontested code disclaimers apply.
  40.  
  41.  
  42. --
  43. --Greg Owen
  44.     gowen@forte.cs.tufts.edu, gowen@jade.tufts.edu
  45. "C Spot. C Spot run. C Spot run without a core dump! Run, Spot, Run!"
  46.