CSC 121A Lab 7 - Spring 2005

Thursday, February 17, 2005
Due: Wednesday, February 23, 2005, 5:00PM

[Course home page] [Java API Documentation]

Answer all numbered and bulleted questions. Upload your answers and program files to the VikingWeb coursework section. Besides uploading your written answers to the VikingWeb, please turn in a printed copy either in class on the due date or leave a copy in the box outside my door later on during the day. (You may turn in the printed copies later than 5PM on the due date, but the files must be uploaded to VikingWeb at or before 5PM.)

You may work in pairs for all parts of this assignment, including the homework exercises.

 

Compiling and Running C Programs

In this lab we will go over the basics of editing and running C programs on the CS server. Follow these steps:

Log into the lab machines as usual. Click on the "Start" menu and then choose the "Run..." option. In the dialog box, type "\\10.16.232.190" and press Enter. After a little while a login screen should show up. Use your Berry email login name as the user name and use your VikingWeb user ID as the password. (You will change this password later on.) Click "OK". After successfully logging in a window like this will show up:

Opne the "Public" directory by double-clicking on it. You should see a web page file in there labeled "policy.html". Open it and read it (it's short and sweet).

Go back to the outer directory. You should see a folder in there with the same name as your login name. In the example above it is called "test". Open that folder. This is your private storage space on the server. Open the "Documents" folder within your private folder. This is where you should store your work for this class. (This is like the LOKI server which you log onto with the Novell login software in the computer lab.)

Create a new folder called "hw07" in your Documents folder. Open the SciTE text editor and type in the hello world program from class. Save it in a file called "hello.c" in the hw07 folder.

Now we will learn how to log into the server for terminal access so that we can compile and run the program on the server. The server is running Mac OS X, which is essentially a Unix-based operating system (on, and for, which the C language was invented).

On the desktop of your computer you should see a link to the program "SSH Secure Shell Client." Launch that program by double clicking on it. You will get a window like the one below. Click on the "Quick Connect" button. Type in the host name: "10.16.232.190" and type in your login name as the user name. Click "Connect" and it will ask you for your password (your VikingWeb ID number). If you want to save the host and login name information as a profile, call it "csserve-yourloginname".

You should now see a terminal (text-only) screen with a prompt like:

Welcome to Darwin!
CSServe:~ test$

      

Type "ls" and press enter. ("ls" in Unix is like "dir" in Windows/DOS). You should see a list of the directories (folders) that were in your private folder when you opened it in one of the earlier steps of this lab. Type "cd Documents" and press Enter. (Unix is more picky about upper and lower-case than Windows. In this version of the operating system, it might actually be kind enough to do what you want if you type "cd documents" with a lower-case d, but in general you have to be careful with Unix.)

Type "ls" and press Enter. You should see the "hw07" directory you created earlier. Type "cd hw07" and "ls" again. You should see the "hello.c" file that you edited.

Now let's compile this file. You run the C compiler by typing:

gcc hello.c -o hello

The compiler is the Gnu C Compiler (GCC), the input source code file is "hello.c" and the output file which we specify with the command-line option "-o" is going to be called just "hello". (Executable files in Unix do not have to end with a ".exe" suffix like in Windows. If you are running GCC on your Windows/DOS computer at home you will need to specify the output file as "hello.exe".) After typing that command, run a "ls" command again. You should see the "hello" file in the directory.

Now, run your program by typing:

./hello

The "./" part indicates the current directory. (One dot refers to the current directory, two dots would refer to the parent directory, etc. and the slash is used to separate between directory names and files.) Your program should print out "Hello world!" in the window.

 

Java Project

You may use the rest of the lab time to work on your project or on the homework exercises below.

 

Homework Exercises

(We have not started Chapter 2 yet in lecture so you may want to wait until the weekend to start working on the later exercises.)

 

Extra-Credit Exercises

In this assignment and following ones, I will list some extra-credit assignments here. These will allow you to add points to your exam grades. They should actually also help you do better on the exams by giving you more practice with different aspects of C programming, so you should try to complete them.

 



Last modified: Thu Feb 17 09:27:32 EST 2005