[OCLUG-devel] write()

James Colannino james at colannino.org
Fri May 20 23:13:10 PDT 2005


Sorry guys, just one more question.  This has me confused.  Consider the
following examples:

Example1:

char c;
int in, out;

in = open ("file.in", O_RDONLY);
out = open("file.out", O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR);

while (read(in, &c, 1) == 1)
    write(out, &c, 1);

Example 2:

char block[1024];
int in, out;
int nread;

in = open ("file.in", O_RDONLY);
out = open("file.out", O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR);

while ((nread = read(in, block, sizeof(block))) > 0)
    write(out, block, nread);

In the first example, you need to pass the pointer to variable c with
both the write() and read() functions, but in the second example, the
block variable, being equivalent to c in the first example, is passed
directly to write() and read() rather than having a pointer to it passed
instead.  Am I missing something?  Thanks again.

James

-- 
My blog: http://www.crazydrclaw.com/
My homepage: http://james.colannino.org/

"A well regulated militia being necessary to the security of a free
state, THE RIGHT of the people to keep and bear arms SHALL NOT BE
INFRINGED." --United States Constitution, Second Ammendment



More information about the OCLUG-devel mailing list