[cs631apue] Lecture 02 warmup

Jan Schaumann jschauma at stevens.edu
Sun Sep 8 15:18:55 EDT 2019


Hello,

As mentioned in class, in order to best prepare for
each week's lecture, I recommend that you read through
the chapters we will cover ahead of time.

In addition, I may occasionally post warmup exercises,
short programs to write or problems to consider that
will help prime your mental cache for the topic at
hand.

For this week, I'd suggest for you to write a small
program that:

- prints the value of the STDIN_FILENO, STDOUT_FILENO,
  and STDERR_FILENO constants
- prints the value of the file descriptors referenced
  via the stdin, stdout, and stderr streams
- open(2)'s afile, then prints the value of the
  resulting file descriptor
- fopen(3)'s a file, then prints the value of the file
  descriptor referenced via that stream

What happens when you open the same file multiple
times with or without closing it again in between?

Try opening the same file twice, then writing
different data to each file descriptor (via
write(2)) - what happens?

Open an existing file that contains some data -
perform alternate read(2) and write(2)s on that file
descriptor.  What does that tell you about the
position in the file as you perform these operations?
How would you go about replacing a specific word in a
file?

Even for this warmup exercise, remember to ensure that
your code complies with our requirements (style,
checklist, general guidelines).

See you tomorrow,
-Jan


More information about the cs631apue mailing list