home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / c / 17054 < prev    next >
Encoding:
Text File  |  1992-11-23  |  1.0 KB  |  30 lines

  1. Organization: Applications Software, Carnegie Mellon, Pittsburgh, PA
  2. Path: sparky!uunet!cis.ohio-state.edu!news.sei.cmu.edu!fs7.ece.cmu.edu!crabapple.srv.cs.cmu.edu!andrew.cmu.edu!rr2p+
  3. Newsgroups: comp.lang.c
  4. Message-ID: <kf4GU6q00VQsM3GGYU@andrew.cmu.edu>
  5. Date: Mon, 23 Nov 1992 13:50:46 -0500 
  6. From: Richard Dale Romero <rickr+@CMU.EDU>
  7. Subject: Re: Multiple &'s in an if statement
  8. In-Reply-To: <1992Nov23.164530.19214@iacd>
  9. References: <1992Nov23.164530.19214@iacd>
  10. Distribution: comp.lang.c
  11. Lines: 17
  12.  
  13. Probably because you're using bit-wise and instead of logical and.
  14. In C, a zero is false and anything else is true.  There is no specification
  15. for what (x == y) returns other than zero or not zero.  So, suppose
  16. that isdigit returns a 2 everytime for true, and
  17. (iscntrl(name[(strlen(path) + 5)]))
  18. returns a 1.  Their bitwise and is 0, ie, false.
  19.  
  20. So, to make it work, just do the following:
  21.  
  22. if(( isdigit[i] & isdigit[i+1] & isdigit[i+2] & isdigit[i+3] & isdigit[i+4])
  23.    && (name[(strlen(path)+5)] == NULL)) {
  24. ...
  25. }
  26.  
  27. -rick
  28.  
  29.  
  30.