Programming Tutorials and Resources
This site uses only free software. It includes a range of links and example programs.

Getting started
The first thing that you need is an appropriate operating system. I use either Red Hat 9 Linux or Cygwin which can be installed and run on computers running Microsoft Windows. Cygwin and Red Hat include the XFree86 windows system which enables X graphics to be displayed. Red Hat comes with a good text editor called gedit. With Cygwin I tend to use nedit, which can be installed along with Cygwin itself. Another good Windows based text editor is J, which is written in Java, but this requires that you download and install Sun's Java. Both operating systems come with the bash shell for entering commands.

GCC is the GNU Compiler Collection, which currently contains front ends for C, C++, Objective-C, Fortran, Java, and Ada, as well as libraries for these languages (libstdc++, libgcj,...). GCC comes bundled with both Red Hat 9 and Cygwin. Unfortunately, the Cygwin set up program currently installs a gpc version that is incomptible with the gcc3.4.4.x, so it is necessary to download   gpc-20051116 from Further frontends are available that need to be downloaded separately. In particular, it is necessary to download GNU Pascal (GPC), which is used in some of the examples on this site. The source distributions include test suites that can be used to check that the compilers are working correctly.

The large-scale discrete event simulation model developed at Newcastle exists in two forms. The interactive version has a Pascal core, with an XView interface. The batch version has a Tk-Tcl interface. Unfortunately these technologies are getting rather 'long in the tooth'. Sun no longer provide XView in recent versions of Solaris and Pascal is no longer supplied as part of the Sun compiler collection. Fortunately XView is now available from in both binaries for common platforms and also source code. I have just started the lengthy task of porting the Sun-based simulation code run on platforms that support gpc/gcc.

A range of over 2,500 free software packages can be downloaded from the Free Software Directory. Some of the programming examples require the use of Make, which is a tool that controls the generation of executables and other non-source files of a program from the program's source files. I have also been recommended DevPascal, which is an integrated development environment for Windows, that can use either GNU Pascal or Free Pascal.

GNU Debugger*
GNU Make*
GNU Pascal
J Text Editor
Red Hat 9
* included in the Cygwin and Red Hat distributions.

Cygwin Users' Guide
EMacs Manuals
GNU Compiler Collection (GCC)
GNU Debugger
GNU Pascal
Index of GNU manuals
J Users' Guide
Red Hat 9 Manuals
Free GNU books
Non GNU free books

Programming in C
I found Eddy's Basic Guide to C Programming very helpful as it provides a very clear set of tutorials on C programming together with lots of examples.

Good books
Alcock, D., 1992, "Illustrating C", Cambridge University Press.
Schildt, H., 2000, "The Complete Reference: C Fourth Edition", Osbourne, Berkely, California. (Excellent book)
Uckan, Y., 1999, "Problem Solving Using C: Structured Programming Techniques", McGraw-Hill, Boston. (Good book)

When I am learning programming languages I find it helpful to develop small examples that each demonstrate some small aspect of programming. I am definitely not an 'expert' or a 'guru' - I completed these examples as a learning experience. There may well be better, neater ways of doing things. If you think this is so, then please drop me an e-mail and I would be pleased to make the necessary updates. The file examples.tar.gz contains all of the examples (a file compressed using gzip, to uncompress type gunzip examples.tar.gz, then to extract the files type tar xvf examples.tar and the files and directories will be recreated.

The C programs can be compiled using the command gcc program_name.c which produces the output file a.out (with Linux) or a.exe (with Cygwin). gcc program_name.c -o executable_name produces an executable called executable_name.

argvprog.c - shows how to pass command line arguments to a C program and illustrates the use of argv and argc
ioexample.c - shows how to write out to the console using printf and get input from the keyboard using scanf.
characters.c - uses the commands getc to read single characters and putc to write single characters.
strings.c - a small example that demonstrates the use of strings.
constants.c - uses constants and the #define preprocessor command.
ex1.c - illustrates a simple program that calculates interest. This includes the use of integer and real variables, the C functions scanf, printf and the use of compiler flags to specify linker options to load libraries.
loops.c - includes three types of loop construction.
operators.c - looks at the use of increment and decrement operators.
ifelse.c - a very short example that illustrates the use of conditional statements.
typedef.c - looks at a simple user defined type.
enumeration.c - uses an enumerator variable to represent days of the week.
simplefunc.c - demonstrates how to call functions is C.
voidcall.c - calls a simple void function.
func.c - another example of the use of functions in C.
recursion.c - uses a recursive function to calculate factorials.
array.c - shows how to use one and two dimensional arrays.
files.c - reading from and writing to files.
mixtypes.c - looks at mixing integer and floating point variables.
struct.c - demonstrates the use of structures (similar to records in Pascal).
c_func_struct.c - passes a structure to a function.
nestedstructure.c - shows the use of a structure within a structure.
pointers.c - a simple example of pointers.
pointertree.c - pointers are used to construct a tree with four levels. A hierarchical code is produced to locate nodes within the tree.
doublelinkedlist.c - pointers and structures are used to produce a double linked list in which events are placed in time order. This is the starting point for the development of a discrete event simulation model.

More advanced examples that include multiple files in Pascal and C and use make (the first name in bold is the directory name). These examples should be kept in separate directories. The examples relate to GCC/GNU Pascal.
ccallextern - this demonstrates how to call an external function in another file. It uses Makefile, externalfunc.c, externalfunc.h and extern.c - to compile the code just type make, make clean will remove old object files.
ccallspascal - the main program is written in C, but it calls a procedure in Pascal and passes variables. The files used are: Makefile, externpascal.c, externpascal.hand pascalfunc.p
pcallsc - this demonstrates how to call a simple C function from a Pascal program. The files include: Makefile, ccall.c, ccall.h and pcallc.p
pcallsc1 - Pascal calls a C function again, but this time an integer variable is passed. The files again include: Makefile, ccall.c, ccall.h and pcallc.p
pcallsc2 - Pascal calls a C function and passes a string variable. The files again include: Makefile, ccall.c, ccall.hand pcallc.p
pcallsc3 - Pascal calls a C function and passes a real variable from Pascal to a double variable in C. The files again include: Makefile, ccall.c, ccall.hand pcallc.p
pcallsc4 - Pascal calls a C function and passes integer, real, string and records to C.  The files again include: Makefile, ccall.c, ccall.hand pcallc.p
pcallsys.p - Pascal makes a system call (to ls). To compile type gpc --automake --executable-file-name pcallsys.p pcallsys.p
Particular thanks are due to Prof. Abimbola A. Olowofoyeku (The African Chief) for help with the examples that investigate the C / Pascal interface.

The following examples illustrate the use of XView interfaces with GPC Pascal programs.
XView1 - Pascal passes a string to a C/XView function that pops up a button with a message. The files include: Makefile, p.p, x_message.c and x_message.h

Powered by

Chris's Home Page                                       This page was last updated on 29th December 2005.

© Dr Christian Hicks, Business School, University of Newcastle upon Tyne