COS 126 Hello, World |
Programming Assignment 0 Due: Thursday, 11:59pm |
The purpose of this assignment is to familiarize you with using the computer and with the mechanics of preparing and submitting assignment solutions. This assignment carries no grade, but you must do the electronic submission. Your goal this week is to learn to use emacs for editing files, gcc for compiling programs, and submit for submitting assignments.
If you have programmed before, you may be able to finish this assignment quickly. If you have not programmed before, or if you are not familiar with the systems that we use, plan to learn the basics in the computer lab in room 101 in the CS building. Don't be afraid to ask for help.Your assignment is to create, compile, and run the following extension of everybody's first C program.
#include <stdio.h> int main(void) { int num; printf("Hello world! Give me an integer:\n"); scanf("%d", &num); printf("Thanks! I've always been fond of %d.\n", num); return 0; }
Completing this assignment involves the following steps.
You can enter a command by typing it in the Terminal window followed by the "Enter" or "Return" key.phoenix.Princeton.EDU%
This customizes several Unix tools specifically for COS 126. (Specifically, it adds /u/cs126/bin to your path, copies our .emacs file to your directory, and creates a dummy web page for you (if you don't already have one). If most of this sounds like gibberish, don't worry about it.)phoenix.Princeton.EDU% /u/cs126/bin/setup126-f00
to create a window for the xemacs text editor, ready for you to type in the file hello.c. The & means to run xemacs in the background, so that you can type other commands without leaving xemacs. The xemacs editor is a bit more complicated than the standard Text Editor on the desktop, but much more powerful, and includes special features designed for writing C programs. If you've used text editors before, you will know how to use xemacs. Just use the pull-down menus and the mouse. You can also launch a tutorial from the Help menu.phoenix.Princeton.EDU% xemacs hello.c &
Enter the C program exactly as it appears above. If you omit even a semicolon, the program won't work. Use the Tab key to get the proper indentation. When you're done, save the program in a file named hello.c.
Working from home. If you are working in a telnet session, you will not be able to use xemacs. Use the command "emacs hello.c" instead. The emacs editor is very similar to xemacs, but lacks the nice graphical user interface.
in the Terminal window. This command runs the C compiler, gcc, which compiles hello.c and leaves an executable file named a.out in your directory. If gcc complains in some way, you mistyped something, and you should check your program carefully. Ask for help if you can't see the mistake.phoenix.Princeton.EDU% gcc126 hello.c
in the Terminal window. This command executes your program. You should getphoenix.Princeton.EDU% a.out
in the Terminal window. Then nothing will happen. You must type an integer (say, 5), and hit Enter, then you will getHello world! Give me an integer:
and the program should terminate. You may need to repeat this edit-compile-execute cycle a few times before it all goes smoothly.Thanks! I've always been fond of 5.
phoenix.Princeton.EDU% submit126 0 hello.c
phoenix.Princeton.EDU% submit126 0
phoenix.Princeton.EDU% enscript126 hello.c
Working from home. The enscript command prints to the printer in the CS lab. The easiest way to use your own printer instead is to ftp the desired file to your computer, and then print as usual under Windows or Mac OS.
and click on netscape's Open button, and enterphoenix.Princeton.EDU% netscape &
courseinfo.princeton.edu/courses/COS126_F2000/
in the Location box. Cruise around the COS 126 Web site; it is essential that you understand what's where and how to get to it. Be sure to fill out the online questionnaire. Also make sure you find the "Assignment Checklist" page, and also be sure to read the COS 126 Collaboration Policy.
Working from home. You will not be able to run netscape from a telnet sessions. Instead use the web browser on your computer.
Working from home. Type the command "logout" when you are finished.