CS 3733 Operating Systems, Spring 2000 Assignment 1 Comments
Here is sample code for a solution to this assignment:
testline.c driver program
readln.c
If I put a circled number on your assignment, it probably refers to one of the
numbers below.
Some comments about this assignment:
- You do not have to use strcpy to copy a single character.
- You can read directly into a character variable with
read(fd,&charvar,1)
- It is better to double the buffer size each time, rather than adding
a fixed value to the size. This is much more efficient when there
are long lines.
- You don't need to use strcat to move a single character.
- If you get lint warnings about functions implicitly declared to
return int or inconsistent usage, it is probably because you left out
some include files.
- You did not include the output from running on the test input file.
- Don't start with a buffer size of 1. It is inefficient as you always
need at least 2 if you count the string terminator. 10 should
be the smallest starting value.
- Reallocating after each character is read in is extremely inefficient.
- You did not handle the case of a zero byte in part 2.
- You must lint both parts of the assignment together in order to
find inconsistencies.
- Do not use the -m and -u options of lint. These will hide some of your
errors.
- Program logic is often simpler if you test early for special cases so you
do not have to undo something you have just done (like incrementing a
variable).
- You are not allowed to change the prototype of readln to suit your needs
in part 2. You must include static variables and write appropriate
functions to return the values of these variables.
- The goal in programming is no longer to write your program in as few lines
as possible. You are not programming in the 60's.
- Use descriptive variable names. It is OK to use i, j, k as loop variables
but not for more general variables. A variable named count
should only be used if it is obvious what you are counting.
- Do not use lseek. This only works for ordinary files and not
for keyboard input, pipes, network connections, etc.
- Unix does not use EOF as a character in a file to denote the end of
the file.
- Don't use the single letter ell (l) as a variable name as in many fonts
it looks like a one.
- Your logic should be arranged so that you only reallocate once. If you
need to do it more often, make it a function.
- You don't have to hand in a copy of the assignment.
- Give you executable a reasonable name, not a.out.
- You should not use 0 to mean NULL, e.g. as a return value from a function
that returns a pointer.
- In main, the return value of readln must be freed in the loop.
- Never declare static variables in an include file. Include files should
only include constant definitions, typedefs, and function prototypes.
Macros should be avoided.
- readln might need to free a buffer if it is returning NULL.
- Some people seem to think that "test output" means a printout of the
assignment.
- Do not put more than one assignment on a line.
- No source code line should be longer than 80 characters.
- Make sure you are using the right version of lint. Execute
    which lint
and it should return something like:
    /opt/SUNWspro/bin/lint