[cs631apue] HW#2

Jan Schaumann jschauma at stevens.edu
Sat Oct 1 15:18:13 EDT 2011


Rob Hoffmann <rhoffman at stevens.edu> wrote:

> When I presented my code in class you mentioned that I should change my  
> char buffer to a void buffer.

We discussed using appropriately typed data structures, and noted that
we do not want to limit our program to only work with one kind of data.
Hence, it was suggested, that we should not use a "char *", but a "void
*" for the buffer into which we read the data.

Now it is worth noting that what we are trying to read and write are
bytes, not "characters".  As UNIX (as such) has no concept of "binary"
files versus "text" files, the data in a "binary" file consists of...
bytes.  Just like the data in a "text" file.

The C programming language guarantees us that a "char" can represent at
least 8 bits (ie a byte), so even though we are not reading
"characters", we can use an array of "char"s and rest assured it will
work for "text" or "binary" files equally well.

See also:
https://secure.wikimedia.org/wikipedia/en/wiki/Byte

> If this is the case, is copying binary  files a required part of the
> assignment

Copying "binary" files is entirely identical to copying "text" files, so
yes, that is a requirement. :-)

> and if so should I be changing  read/write to fread/fwrite in order to
> accommodate this?

There is no need to use fread(2)/fwrite(2) over read(2)/write(2).  Check
the function prototypes -- you'll note that read(2) acts on a "void *"
buffer (and using a "char *" buffer here will work, too).

-Jan


More information about the cs631apue mailing list