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 n; 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.
to create a window for the emacs text editor, ready for you to type in the file hello.c (the & means to run emacs in the background, so that you can type other commands without leaving emacs). The emacs editor is a bit more complicated than the standard Text Editor on the desktop, but much more powerful, and you will be able to use emacs in terminal or telnet sessions on your own computer. If you've used text editors before, you will know how to use emacs. Just use the pull-down menus and the mouse. You can also launch a tutorial from the Help menu. Enter the C program exactly as it appears above. If you omit even a comma, the program won't work. You can use the Tab key or spaces to get the indentation. When you're done, save the program in a file named hello.c.emacs hello.c &
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 and get help if you can't see the mistake.gcc126 hello.c
in the Terminal window. This command executes your program. You should geta.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.
/u/cs126/bin/submit 0 hello.c
/u/cs126/bin/submit 0
lpr -Ppsr hello.c
and click on netscape's Open button, and enternetscape &
http://courseinfo.princeton.edu/courses/COS126_F2000/
in the pop-up dialog box. Cruise around the COS 126 Web; it is essential that you understand what's where and how to get to it. Be sure to fill out the online questionnaire and read the COS 126 Collaboration Policy.
To log out, position the mouse over the background, i.e., not over any windows, click the right mouse button, and select "Logout". Alternatively, you can just click the "EXIT" button in the Control Panel. Don't forget to log out!