EG2069 Some notes on the programming exercises


Your account and your password

As an engineering student, you have two user accounts at the university, one central account administered by DISS, and an engineering account administered by the computing officer at the department. The two accounts also have separate file areas, so files on one account can't be directly accessed from the other. This can frequently be confusing. Both accounts have the same username, but not necessarily the same password.

Working in a Unix environment

This course is taught in a Unix environment, which means that you have to log into a Unix server to write your programs. It is best if you use one of the engineering servers - goss or hex, but it is also possible to use sysa if you prefer it, or if you for some reason can't get into one of the engineering department servers.

As you may recall, you were given a handout with some simple Unix commands at the beginning of the C programming practicals. If you have lost it, a slightly edited version can be found here.

Once you are logged into the server, you have a terminal window on your screen, from which you can start a program, such as:

When you start a program, it will normally run in the terminal window, and you will not be able to start another program until the first program finishes. Some programs, such as the editors dtpad and nedit, start in a separate window on your screen. If you start these programs normally, you still won't be able to use your terminal window for anything else until the editor is closed. There is a smart trick you can use in these cases, however - if you add " &" (e.g. "dtpad &") to your command, you can use your terminal window immediately, without having to close the editor window.

Your programs

Your programs will exist in 2 versions. One is called the source code, this is the text file containing the program you have written. For a C program, the source code files end in ".c", such as "file1.c" (other languages use other filename endings, such as "file1.for" (Fortran), or "file1.pas" (Pascal)). You can edit this program by using an editor, such as dtpad, nedit, or pico. This file contains your program, but the computer cannot run this program directly! It needs to be compiled first. The compiler can be called by the cc command, e.g.:

cc file1.c

If the compilation was successful, i.e. the compiler found no errors, the program will be written to a file called a.out. This is called the executable file, and this is the form which can be understood by the computer. If you try reading the file, it is very unlikely that you would be able to make any sense of it. The program can then be run by typing "a.out" in your terminal window. It is normally better to give the executable a different name, however, and this can be done either by renaming the file (the mv command, remember?) or by using the -o option to specify the executable file name when running the compiler:

cc file1.c -o file1

In this case the executable file will be "file1", and the program can be run by typing "file1" in the terminal window.

In programming you will normally have to edit your program, compile it and run it several times in order to get all the bugs out of it.


Author : Helge Nareid Current Admin: Gorry Fairhurst G.Fairhurst@eng.abdn.ac.uk