CS35: Assignment 2

CS35: Programming and Problem Solving
Ray Ontko
Department of Computer Science
Earlham College

Due Monday, 1999/08/30

Note: Some of the following will be completed in Lab on Friday, 8/27.

Reading Assignment

Read sections 2.1 and 2.2 of Deitel and Deitel. Optionally, read section 1.1 of Kernighan and Ritchie.

Lab Assignment

  1. Obtain your username and password for the Computer Science computer network from your instructor.

  2. Use the "telnet" program to connect to "athenax.pvm.cs.earlham.edu", where x is a number 0..9 or a letter a..f.

    On the Macintosh Lab systems you should:

    1. Launch Better Telnet, a popular terminal emulator for the Macintosh. You'll find it in the Applications folder listed under the name Better Telnet Fat.
    2. Under the File menu, pick Open.
    3. Fill in "athenax.pvm.cs.earlham.edu" as your destination, where x is a number, 0..9, or a letter, a..f.
    4. Click the button to connect. Within a few seconds, you should see a window appear with a prompt for the your "Username:".
    5. Enter your username followed by the Enter key. You will be prompted for your password.
    6. Enter your password followed by the Enter key. Do not be alarmed that you can't see what you are typing (this is a security feature, in case someone is looking over your shoulder). If all is well, you will see a prompt that ends with a "$". If not, you will be prompted to re-enter your username and password.

  3. Use the "pico" editor to create your first C program.
    1. At the command prompt, type "pico hello.c". You should see a bar across the top line of the terminal window, and a menu of options occupying the bottom few lines.
    2. Type in the following program, letter for letter, typing the Enter key at the end of each line, or the delete key to erase any typing errors. Use the arrow keys to move the cursor around as needed. For now, just enter exactly what you see. We'll worry about what it means later. The purpose of this exercise is to get you familiar with some of the program-creating tools.
      #include <stdio.h>
      
      main()
      {
          printf( "Hello, world.\n" ) ;
      }
      
    3. When you're done typing, hold the CTRL key down (like you would a shift key) and type the X key. (This key combination corresponds to the ^X you see at the bottom of the Pico screen). You will be prompted for whether you wish to "Save modified buffer".
    4. Type the "Y" key to indicate that you wish to save your changes. You will then be prompted for the "Filename to write".
    5. Type the Enter key to indicate that you wish to write your changes to the file called "hello.c". You should now be back at the "$" command prompt.

  4. Use the "cc" command to compile your program. During this step, the file you created will be translated from the "C" language into machine language, that is, into a language that can be executed directly by the computer hardware. Simply enter the command
    cc -o hello hello.c
    

    This command instructs the C compiler ("cc") to create an output file ("-o") named "hello" by reading the program file "hello.c".

    If all goes well, you should simply get another "$" command prompt. If something isn't exactly right with the program, you may get a number of error messages. If you get error messages, read them carefully, and use "pico hello.c" to go back and see if you can change your program.

  5. Use the "ls" command to see the files in your directory. You should see two files, "hello" and "hello.c".

  6. Use the "ls -l" command to see a detailed listing of the files in your directory. In addition to the names, "hello" and "hello.c", you will see additional information about the files including: security information, size information, and the date and time at which the file was created or modified.

  7. Now, you're ready to run your program. You can do this by typing "./" in front of the name of your compiled program. (Later we'll learn how to do this without the "./".)
    ./hello
    
    You should see the computer respond with a message "Hello, World!". Congratulations. You've run your first program.

  8. Try making changes to your program, and recompile and re-run it. See what kind of errors you can get. What changes can you make and still have a working program?

  9. When you're done, be sure to logout.
    1. Use the "logout" command to log off the athenax machine, and
    2. close the terminal window, and
    3. exit Better Telnet

Copyright © 1999, Ray Ontko (rayo@ontko.com).