Date: Sat, 15 Jan 2000 19:26:29 +0000 From: Ben Smithurst <ben@scientia.demon.co.uk> To: Carlos Maracabay <caradusa@yahoo.com> Cc: freebsd-questions@FreeBSD.ORG Subject: Re: Language C on Freebsd Release 3.3 Question. Message-ID: <20000115192629.A970@strontium.scientia.demon.co.uk> In-Reply-To: <20000115185839.4740.qmail@web113.yahoomail.com> References: <20000115185839.4740.qmail@web113.yahoomail.com>
index | next in thread | previous in thread | raw e-mail
Carlos Maracabay wrote:
> #include <stdio.h>
> #include <fcntl.h>
> #include <sys/types.h>
> #include <unistd.h>
fine, but I tend to put <sys/types.h> 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
help
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20000115192629.A970>
