Date: Mon, 17 Jan 2000 01:48:26 +0200 From: Giorgos Keramidas <charon@hades.hell.gr> To: Carlos Maracabay <caradusa@yahoo.com> Cc: freebsd-questions@FreeBSD.ORG Subject: Re: Language C on Freebsd Release 3.3 Question. Message-ID: <20000117014826.B389@hades.hell.gr> In-Reply-To: <20000115185839.4740.qmail@web113.yahoomail.com> References: <20000115185839.4740.qmail@web113.yahoomail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
On Sat, Jan 15, 2000 at 10:58:39AM -0800, Carlos Maracabay wrote: > Hi! > > I have problems making a simple program that opens > a file, to view it contents on the monitor scream... > what's the problem in this source file, to do this, in > Freebsd?? > > Any help will be appreciated. > Thanks for your time! > > Regards, > Dimetriov. > #include <stdio.h> > #include <fcntl.h> > #include <sys/types.h> > #include <unistd.h> > > > > > main(int argc, char *argv[]) > { > > int f1,n; > char buf[BUFSIZ]; > > if(argc != 2) > printf("Argument meesing\n"); > if(f1 = open(argv[1], O_RDONLY,0) == -1) The above statement, bearing in mind that == will happen first, will be equivalent to the fully parenthesized: if (f1 = (open(argv[1], O_RDONLY, 0) == -1)) which depending on whether open() succeeds or not, will always set f1 to C's notion of true or false, either 1 or 0 respectively. You can bet that you'll be reading from the wrong descriptor if this happens, since both 0 and 1 are descriptors already assigned to standard input and standard output ;) > printf("cp cant open \n"); __^^__ I surely hope you're not calling your executable `cp' with /bin/cp in your PATH before the current directory... and expect to call your program without a leading ./ as in: % ./cp FILE Ciao. -- Giorgos Keramidas, < keramida @ ceid . upatras . gr > "What we have to learn to do, we learn by doing." [Aristotle] To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20000117014826.B389>