From owner-freebsd-questions Sun Jan 16 15:51: 4 2000 Delivered-To: freebsd-questions@freebsd.org Received: from mx2.x-treme.gr (mx2.x-treme.gr [212.120.192.15]) by hub.freebsd.org (Postfix) with ESMTP id 2FB2014E20 for ; Sun, 16 Jan 2000 15:50:49 -0800 (PST) (envelope-from keramida@diogenis.ceid.upatras.gr) Received: from hades.hell.gr (pat44.x-treme.gr [212.120.197.236]) by mx2.x-treme.gr (8.9.3/8.9.3/IPNG-ADV-ANTISPAM-0.1) with ESMTP id BAA05704; Mon, 17 Jan 2000 01:50:41 +0200 Received: (from charon@localhost) by hades.hell.gr (8.9.3/8.9.3) id BAA00438; Mon, 17 Jan 2000 01:48:26 +0200 (EET) (envelope-from keramida@diogenis.ceid.upatras.gr) Date: Mon, 17 Jan 2000 01:48:26 +0200 From: Giorgos Keramidas To: Carlos Maracabay Cc: freebsd-questions@FreeBSD.ORG Subject: Re: Language C on Freebsd Release 3.3 Question. Message-ID: <20000117014826.B389@hades.hell.gr> Reply-To: keramida@ceid.upatras.gr References: <20000115185839.4740.qmail@web113.yahoomail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 1.0pre3i In-Reply-To: <20000115185839.4740.qmail@web113.yahoomail.com> Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG 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 > #include > #include > #include > > > > > 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