Computer Science 126
Fall 1996

  • What's New · What's Changed
  • Schedule
  • General Information
  • Assignments
  • Lecture Slides
  • Help!

  • Lab TA Schedule · Emacs Quick Reference · Gdb Tutorial
    Postscript Cheatsheet · A First Guide to PostScript · Postscript Operators
    TOY Quick Reference · Sample TOY Programs
    Sample C Programs · libmisc Code

    compile.c prints the Polish suffix for its expression; should our eval.c print Polish suffix, too?
    No; the postorder function is just for debugging. You may want to print the Polish suffix while you're developing your program, but remove the call to postorder before you submit your final version.
    Assignment 10's install function (defined in table.h) has different arguments than lookup2.c's insert function. Can I copy insert into my table.c and call it from install?
    Yes; this is probably the easiest way to implement table.c. Make sure your implementation of install reads and writes the global variable root correctly (root must be defined in your table.c).
    Does precedence matter in assignment 10? That is, should we interpret a*b+c as (a*b)+c or a*(b+c)?
    You can ignore precedence, so either interpretation is fine. Technically, the grammar in the assignment is ambiguous, because it doesn't specify precedence. If you feed a*b+c to compile.c, you'll see that the generated code computes a*(b+c).
    Can we use strcmp and the other functions declared in string.h in assignment 7?
    Yes, most definitely! Unless instructed otherwise, always use library functions whenever possible.
    I read and reread assignment 4, but I'm still not sure exactly what I'm supposed to do. Please clarify!
    You're to implement the 5 functions specifed in /u/cs126/examples/rat.h in the file rat.c, and a program in testrat.c that computes x2/(x - 1) for each of its rational arguments x and displays the intermediate values. Here's a three-step strategy for completing assignment 4:
    1. Implement the 5 functions using the simplest possible algorithms, and using the gcd implementation given in assignment 4. Don't worry about program arguments in testrat.c; just "wire in" specific rational numbers with code like
      Rational x;
      reduce(x, 2, 3);
      Edit these values to try other values. This is enough to get your rational arithmetic functions working.
    2. Change your testrat.c to handle program arguments (use sscanf to dismantle each argument; see the bottom of p. 383 in Deitel and Deitel), and implement the improvement to the gcd code described in assignment 4. At this point, submit rat.c and testrat.c; you can submit the final version of rat.c again after step 3.
    3. Compile /u/cs126/examples/area.c with your rat.c as shown in assignment 4 and run a.out 40 50; you should see the wrong output for 50, which occurs because of overflow in your rational arithmetic functions. Think about how to revise your implementations of add, multiply, and divide to avoid overflow in some cases. Explain your revisions in your readme, and submit readme and your revised rat.c.
    Yipes! I accidently deleted one of my C files (e.g., rat.c); what do I do?
    Each night, CIT saves copies of all files that were created or changed during the day. If you zap a file, send a message to restores@phoenix asking for the most-recent backup copy. Be sure to specify the full path for the file, e.g., send a message like

    Please restore /u/drh/4/rat.c from the most recent backup. Thanks, dave h.

    Your home directory is named "/u/yourlogin". You'll need to re-edit the restored file to incorporate the changes you made between the time it was saved and the time you zapped it. You can also use the /u/cs126/bin/submit command to save copies of your files. When you have part of your program working, submit it, which makes a copy in the COS 126 submission directory. Later, when you complete your program, submit it again. Only the most recent copy is saved, if you accidently delete a file, we can email the most recently submitted copy back to you.
    When I use the command "echo Hello world | a.out | od -b", the output is different than what is shown on the assignment 3 Web page; why?
    I botched the command: use od -c, not od -b. If you use od -b, here's what you get:
    % echo Hello world | a.out | od -b
    0000000 143 132 076 007 222 212 126 100 160 266 045 141
    0000014
    What does the error message "cpp: hello.c:10 No newline at end of file" mean?
    Your file (hello.c in this case) doesn't end with a new-line character. You can add some by editing the file, positioning the cursor just after the last "}", and hitting the Enter key a couple of times.
    How to I put my name and precept number in C programs, like hello.c?
    You put them in a comment, which is text enclosed in a /* */ pair, e.g., add the line
    /* Dave Smith, precept 1 */
    to the beginning of your program. Don't forget the closing */.
    When I type "lcc hello.c", the computer says "lcc: Command not found", and when I type "a.out", it says "a.out: Command not found". What did I do wrong?
    You did nothing wrong. The problem is that you don't have "." and /usr/princeton/bin in your path. Add the line
    set path=( . /usr/princeton/bin $path )
    to your ".cshrc" file, creating .cshrc if necessary. If you already have a set path statement in .cshrc (see below), you can combine them into the one statement
    set path=( . /usr/princeton/bin /usr/princeton/bin/X11 /u/cs126/bin $path )
    What is a "path" and how do I add /usr/princeton/bin/X11 and /u/cs126/bin to it?
    See pp. 138-9 in Hahn, Student Guide to UNIX. To change your path, add the line
    set path=( /usr/princeton/bin/X11 /u/cs126/bin $path )
    to the file ".cshrc" (that's "dot" c s h r c) in your login directory.
    How do I configure Netscape 3.0 so I can browse the lecture slides?
    Launch netscape-3.0. Follow the menus and tabbed dialogs to the "Helpers" page:

    Options
    General Preferences
    Helpers

    Highlight "application/pdf" (scrolling to it, if necessary), click "Edit", and click the "Plug in" box. Then click the "OK" buttons to back out of this briar patch.You should then be able to browse the Acrobat PDF files for the lectures.
    How do I change precepts?
    See Mrs. McDermott in CS Bldg. 410; you can also send her email at dmcd@cs.

    Copyright © 1996 David R. Hanson / drh@cs.princeton.edu
    $Revision: 1.14 $ $Date: 1996/12/06 15:11:52 $