COMP20005 workshop 1
Welcome to the first workshop for the subject COMP20005 Engineering Computation. The materials for the subject are: the textbook Programming, Problem Solving, and Abstraction with C by Alistair Moffat, and the lecture notes. With a little searching, you should be able to find lots of online introductory materials on C programming. Here are some:
- The C Book — an introductory textbook on C programming.
- cplusplus.com — a reference on the C library. This has lots of sample code that demonstrate each function in the C standard library.
- Fundamentals of C Programming — a set of video tutorials that are aimed at beginners.
- C Programming Tutorials — another set of video tutorials for beginners to the C language.
- Getting to know each other and how you can contact your tutors.
- Where and how to get help.
- Be familiar with the software environment that we will use in this subject. We will use jEdit for writing up our programs and MinGW to compile our programs.
- Step through the process of writing a program, compile the program, run the program, and debug the program.
- Exercises 1.3 and 2.6 in the textbook.
In workshop 1, we will cover the following topics:
Compile your program
When you go through the write, compile, run, and debug loop, you will most likely have to compile your program several times. For example, if your source file is called hello.c, you would compile it from the command line by using the following incantation:
gcc -Wall -ansi -o hello hello.c
If you do this several times, it can get boring and tedious. To speed up the compilation process, you can write a little program called a shell script. Under Windows, it’s called a batch file, but under Linux and Mac OS X it’s called a shell script. Assuming that you’re using Windows, the batch file would take the name of your source file, but without the extension “.c”, and compile your source file. To create the batch file, create a file with the name compile.bat. Put the following content into the batch file:
gcc -Wall -ansi -o %1 %1.c
Note that %1 is the percentage symbol followed by the number one. Make sure that your batch and source files are in the same directory. From the command line, you would compile your program as follows:
Notice that the only argument for your batch file is the name of your source file, but without the extension “.c”. You should then be able to run your program (under Windows) by issuing the command
I will hold office hours each Thursday from 12pm to 2pm in Doug McDonell building 168, room 6.13. Other times are by appointment only. Remember that if you contact your lecturer or tutors via email, make sure that you use the subject prefix “[COMP20005]”. Otherwise, we will not pick up your email.