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:
  1. You do not have to use strcpy to copy a single character.
  2. You can read directly into a character variable with read(fd,&charvar,1)
  3. 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.
  4. You don't need to use strcat to move a single character.
  5. 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.
  6. You did not include the output from running on the test input file.
  7. 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.
  8. Reallocating after each character is read in is extremely inefficient.
  9. You did not handle the case of a zero byte in part 2.
  10. You must lint both parts of the assignment together in order to find inconsistencies.
  11. Do not use the -m and -u options of lint. These will hide some of your errors.
  12. 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).
  13. 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.
  14. 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.
  15. 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.
  16. Do not use lseek. This only works for ordinary files and not for keyboard input, pipes, network connections, etc.
  17. Unix does not use EOF as a character in a file to denote the end of the file.
  18. Don't use the single letter ell (l) as a variable name as in many fonts it looks like a one.
  19. Your logic should be arranged so that you only reallocate once. If you need to do it more often, make it a function.
  20. You don't have to hand in a copy of the assignment.
  21. Give you executable a reasonable name, not a.out.
  22. You should not use 0 to mean NULL, e.g. as a return value from a function that returns a pointer.
  23. In main, the return value of readln must be freed in the loop.
  24. Never declare static variables in an include file. Include files should only include constant definitions, typedefs, and function prototypes. Macros should be avoided.
  25. readln might need to free a buffer if it is returning NULL.
  26. Some people seem to think that "test output" means a printout of the assignment.
  27. Do not put more than one assignment on a line.
  28. No source code line should be longer than 80 characters.
  29. Make sure you are using the right version of lint. Execute
        which lint
    and it should return something like:
        /opt/SUNWspro/bin/lint