From owner-freebsd-questions Sat Jan 15 13:13:39 2000 Delivered-To: freebsd-questions@freebsd.org Received: from scientia.demon.co.uk (scientia.demon.co.uk [212.228.14.13]) by hub.freebsd.org (Postfix) with ESMTP id 655AC14A21 for ; Sat, 15 Jan 2000 13:13:31 -0800 (PST) (envelope-from ben@scientia.demon.co.uk) Received: from strontium.scientia.demon.co.uk ([192.168.91.36] ident=exim) by scientia.demon.co.uk with esmtp (Exim 3.12 #1) id 129YqD-000Izq-00; Sat, 15 Jan 2000 19:26:29 +0000 Received: (from ben) by strontium.scientia.demon.co.uk (Exim 3.12 #1) id 129YqD-0000Gm-00; Sat, 15 Jan 2000 19:26:29 +0000 Date: Sat, 15 Jan 2000 19:26:29 +0000 From: Ben Smithurst To: Carlos Maracabay Cc: freebsd-questions@FreeBSD.ORG Subject: Re: Language C on Freebsd Release 3.3 Question. Message-ID: <20000115192629.A970@strontium.scientia.demon.co.uk> References: <20000115185839.4740.qmail@web113.yahoomail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 1.0i In-Reply-To: <20000115185839.4740.qmail@web113.yahoomail.com> Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG Carlos Maracabay wrote: > #include > #include > #include > #include fine, but I tend to put first, since other headers may depend on it. It doesn't seem to matter here, though. > main(int argc, char *argv[]) You should explicitly declare "main" as returning "int". > if(argc != 2) > printf("Argument meesing\n"); You should probably exit() after printing that error message. > if(f1 = open(argv[1], O_RDONLY,0) == -1) Here's the real problem. You're assigning to "f1" the value of open(...) == -1, which will be 1 if open fails, and 0 if it doesn't. this will cause your code to try to read from standard input, or output, respectively. You need parentheses around the "f1 = open(...)" part, as you did in the n = read loop below. If you compile with the -Wall flag to cc, you would have seen these problems yourself. :-) > printf("cp cant open \n"); again, you should exit, and it would be good practice to say which file you can't open, and why (e,g, strerror(errno)). > while((n = read(f1,buf,BUFSIZ)) > 0) > if(write(1,buf,n) != n) #I think here is > my problem no, that's fine. -- Ben Smithurst | PGP: 0x99392F7D ben@scientia.demon.co.uk | key available from keyservers and | ben+pgp@scientia.demon.co.uk To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message