What is wrong with this code ?

James Hu jxh at phobos.cis.ksu.edu
Sun Dec 10 18:14:35 AEST 1989


In article <1156 at nsscb.UUCP> nrg at 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 at phobos.cis.ksu.edu     | Kansas State University |
| 642 Haymaker Hall    | SIRIUS at KSUVM.BITNET        | Dept. of Computing and  |
| Manhattan, KS 66502  | ...!phobos.cis.ksu.edu!jxh | Information Sciences    |
`-----------------------------------------------------------------------------'



More information about the Comp.lang.c mailing list