CS 3210 - Lab1 - Hello World

Or: "Getting familiar with the UNIX programming environment"

All computer science classes are required by law to include one of three things: (1) The OSI 7-layer model, (2) The "Towers of Hannoi" problem, or (3) a "Hello World" program. You lucky guys get to do "Hello World".

Step-by-Step

Step #1: Make a unix/lab1/ Directory

If you have not already done so, create a directory called 'unix' under your home directory by typing mkdir unix. Change into that directory by typing cd unix. Once there, create another directory called 'lab1' by typing mkdir lab1. Now change into that directory by typing cd lab1.

Now you've got everything set up that you need to. Please note that all the directory and filenames you will use should be lowercase and contain no spaces.

Step #2: Choose an Editor

There are a whole slurry of text editors that you can use on gautama. They all basically accomplish the same thing, editing text, so it doesn't much matter which one you choose, as long as it's one that you're comfortable with.

Here's a list of editors you might use:

I will help you with vi. You're on your own for the others.

Step #3: Write Your "Hello World" program

Start by typing vi hello.c. Hit 'i' to insert. Then type in the following:

/*
 * Your name
 * Lab1 - Hello World
 * CS 3210 - Unix programming
 */

#include <stdio.h>

int main()
{
	printf("Hello world!\n");

	return 0;
}

Type ESC then ":wq" RETURN to quit and save.

The commented lines at the top are very important; I want to see them at the top of every assignment you turn in. If you don't put those lines on there, I won't (can't!) give you credit.

Step #4: Compile Your Program

You do this by exiting out of your editor and at the command line typing:

	gcc hello.c -o hello

An online manual for gcc and it's options can be found right here

Step #5: Run Your Program

You do this by typing ./hello at the command line. Please note that you must type the ./ before the hello or it won't work. This is because the current working directory is not included in your PATH. (Type echo $PATH if you want to see what it contains.)

Step #6: Write a Makefile

But wait? I thought I was done?

Nope. I want you to make a makefile that you can use to compile your program. These will become more important later on and save you lots of typing.

Type vi Makefile and insert the following lines into it:

all:
	gcc hello.c -o hello

Note that there is a single TAB (not a space) in front of the "gcc" command. Yes, it matters.

Save it as Makefile. The 'M' must be capitalized.

Step #7: Test your Makefile

You do this by typing make at the command line. You should see the line from your Makefile get executed. Nifty, eh?

An online manual on using make can be found right here

Files

For this lab you will need a grand total of one directory (called "lab1") and the following two files:

This lab is due the class after the Midterm. I want you to finish this in class, though.