Spring, 2009

CSU 380 Lab 1: Introduction

Purpose:

This is an introductory lab. Almost all of you will find this easy and trivial , but we want to make sure everybody knows how to get started. In this lab you will learn how to write, compile and run a simple C program. Lab policy:

You may work in groups of two students. You CAN help and speak with other students and other groups. Tentatively, the check-off of any lab is due at the beginning of the successive lab (this may change). So if this lab is posted on a Monday, you must get it checked off by the following Monday.

How to log in:

In order to log into a machine you need to have an account. Get one if you don't have one already. You are provided with two things: a login (e.g. jcasey) and a secret password (e.g. mtsh34op [no, it is not my password]).
Just follow the instruction on the monitor to log in. You will be required to type your login (in clear) and then your password (it will not appear on the monitor to prevent people around you from seeing it). We're not sure how you can read these instructions if you haven't logged in.

Task 0: Log in


Write, compile and run a simple C program A C program is made up of one or more files. The program we are going to write is really simple. It will be contained in one simple C file.

Open a console and type xemacs hello.c &. XEmacs is a program that allow you to edit text files. You need to know two things:

Press Ctrl + X + C to Save AND exit
Press Ctrl + X + S to simply save
This is the code of your first program (copy it now):
#include <stdio.h> 
 
int main() { 
 
  printf("\n\nHello World!!!\n\n"); 
  return 0; 
 
}

After you have done it save and close the Xemacs window (Ctrl+ X + C). Now you have written your first C program. Try to type "ls" to see the list of all the files in your current directory.
A C program is a text file. You cannot execute it. You need to compile it and produce an executable file. In order to do that, type gcc -o hello hello.c. Type "ls" after the compilation finishes, and you'll see that the compiler has produced a new file called hello. You can execute it now by typing ./hello.

Task 1: Your first C program

Follow the instructions of the preceding paragraph and write, compile and execute the "hello world" program.

Last updated: 1/18/2009