CSC 407: Systems II
Homework 1
Due by 11:59 pm on Sunday, January 17
Reading
Read the lecture 1 notes
and experiment with the code discussed there. To access the code,
log into perko406.cdm.depaul.edu and copy the lecture1
directory to your home directory from my public directory /home/lperkovic/public/
as follows:
$ cp -r /home/lperkovic/public/lecture1 .
Assignment
Log into perko406.cdm.depaul.edu (as shown in the lecture notes) and copy
zipped file hw1.zip from /home/lperkovic/public/
to your home directory. For example:
$ cp /home/lperkovic/public/hw1.zip .
The file hw1.zip will be in your current directory:
$ ls
hw1.zip
Now unzip the compressed file
$ unzip hw1.zip
Archive: hw1.zip
creating: hw1/
inflating:
hw1/Makefile
inflating: hw1/hw1.c
inflating: hw1/data.txt
and move to newly created directory hw1:
$ cd hw1/
In this directory you will find C file hw1.c that you will
work on and file Makefile which contains the UNIX shell
command that will submit your completed homework to the dropbox on
the Linux box:
$ ls
data.txt hw1.c Makefile
Open file hw1.c for editing using the editor of your
choice (emacs, vi, nano, ..) and do the homework using the
instructions below. When done, submit the homework as
follows:
$ make submit
chmod 600 hw1.c
cp -i hw1.c /home/lperkovic/dropbox/hw1-`whoami`.c
Notes:
- DO NOT MODIFY THE NAME OF THE FILE hw1.c. The
command make submit will submit to the dropbox a file
called hw1.c and no other.
- You may submit multiple times but each submission will
overwrite the previous one.
- Do not modify file Makefile.
Problem
1. File hw1.c contains skeleton code
that you will complete as follows:
- You will create and initialize a 2-D table of num_rows
rows and num_columns columns containing entries of
type entry_t (defined in hw1.c). The c
and n fields of each entry should be initialized to '
' (blank space) and 0, respectively.
- You will then print the table. By adding parentheses, commas,
and blank spaces as needed and using formatted output, your
output should be:
( ,0) ( ,0) ( ,0) ( ,0)
( ,0) ( ,0) ( ,0) ( ,0)
( ,0) ( ,0) ( ,0) ( ,0)
- Next, you will open the (provided) file data.txt,
read it line by line and update table entries based on the
content of each line as follows: if the line contains (i,j):(d,m)
(where i, j, and m are integers
and d is a character) you will update the table entry
in row i and column j so field c
is 'd' and field n has value m.
- When the end of the file data.txt is reached, close the file
and print the updated table. You should obtain:
(f,4) ( ,0) ( ,0) ( ,0)
( ,0) (x,7) ( ,0) ( ,0)
( ,0) ( ,0) ( ,0) (d,9)
- Finally, free the memory space allocated for the table.