COS 126 Hello, World using Your Windows PC |
Programming Assignment 0 Due: Wednesday, 11:59pm |
The purpose of this assignment is to familiarize you with the mechanics of preparing and submitting assignment solutions. This assignment carries no grade, but you must do the electronic submission. Follow these instructions if you want to use the LCC-Win32 system on your Windows PC. We provide different instructions if you prefer to use OS X on your Macintosh or Unix on the arizona workstations. Your goal this week is to learn to use LCC-Win32 system for editing and compiling programs.
If you have programmed before and are familiar with the Windows operating system, you may be able to finish this assignment quickly on your own. If you have not programmed before, or are hesitant about using Windows, we recommend that you bring your laptop and a network cable to the Friends center lab, and work on the assignment there. The lab will be staffed with knowledgeable TAs who can assist you. Don't be afraid to ask for help.
Your assignment is to create, compile, run and submit three short C programs. In addition, you will edit and submit a descriptive file called readme.txt with each of your assignments. (Instructions for the readme file are on the checklist for each assignment.)
PROGRAM 1 hello.c : Create, compile, run and submit 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; }
PROGRAM 2 hello-while.c : Create, compile, run and submit Hello World Exercise #5.
PROGRAM 3 hello-if.c : Create, compile, run and submit Hello World Exercise #6.
Completing this assignment involves a number of steps that are described below. The instructions refer to Program 1, but will be the same for Programs 2 and 3. These instructions were written for Windows 2000 users, but you should be able to adapt them if you are using a different version of Windows.
|
The mkdir command creates a new directory; the cd command changes the current working directory. After executing these commands, your working directory is the newly created C:\cos126\hello. All of your files for Assignment 0 will go here.C:\WINDOWS>cd C:\ C:\>mkdir cos126 C:\>cd cos126 C:\cos126>mkdir hello C:\cos126>cd hello C:\cos126\hello>
Don't be scared by the DOS Command Prompt - you will only need to use a few basic commands. Keep this window open. You will use it in the Compiling and Executing sections of this assignment.
|
Now you are ready to write your first program.
and click OK.c:\cos126\hello\hello.c
|
If lcc complains in some way, you mistyped something, and you should check your program carefully. Ask for help if you can't see the mistake.C:\cos126\hello\>c:\lcc\bin\lcc126 hello.c
C:\cos126\hello\>c:\lcc\bin\lcc126 hello.c C:\cos126\hello>c:\lcc\bin\lc -A -ansic hello.c
|
C:\cos126\hello\>hello
This command executes your program. You should get
in the 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.
|
choose the Assignment Submission menu option, and follow the instructions provided.http://www.princeton.edu/~cs126
|
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 0 Checklist" page, and also be sure to read the COS 126 Collaboration Policy.http://www.princeton.edu/~cs126