Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!uunet!deimos.cis.ksu.edu!phobos.cis.ksu.edu!jxh From: jxh@phobos.cis.ksu.edu (James Hu) Newsgroups: comp.lang.c Subject: Re: What is wrong with this code ? Summary: comparison operators Message-ID: <5272@deimos.cis.ksu.edu> Date: 10 Dec 89 07:14:35 GMT References: <1156@nsscb.UUCP> Sender: nntpd@deimos.cis.ksu.edu Reply-To: jxh@phobos.cis.ksu.edu (James Hu) Organization: Kansas State University, Dept of Computing & Information Sciences Lines: 20 In article <1156@nsscb.UUCP> nrg@nsscb.UUCP (G.Narotham Reddy) writes: [...] >stat(argv[1], &nfile); >if (nfile.st_mode & S_IFMT == S_IFREG) >printf("%s regular file\n", argv[1]); [...] The problem is in the order of precedence of the == and & operation. Just add parentheses : if ((nfile.st_mode & S_IFMT) == S_IFREG) ... -- | James Hu | jxh@phobos.cis.ksu.edu | Kansas State University | | 642 Haymaker Hall | SIRIUS@KSUVM.BITNET | Dept. of Computing and | | Manhattan, KS 66502 | ...!phobos.cis.ksu.edu!jxh | Information Sciences | `-----------------------------------------------------------------------------'