C TUTORIAL:-PART 1 (c) Copyright 1996 Richard Harvey You are probably thinking 'Oh no! Not another C tutorial'. I know how you feel. In my quest to learn how to program in C, I read dozens of tutorials and books and hardly learnt anything from them. Recently, however, I attended a course in C programming and software design and everything (well almost everything) became crystal clear. The trouble with most tutorials and books is that they go too fast. The first few parts, or chapters, go quite easily but before you know it they become either too technical, or expect you to know things in depth which they skimped over. This tutorial aims to be different. We will cover tha main aspects of C programming at an easy pace and cover them in depth, this may mean repeating certain things but this is only to make sure you understand the underlying principles sufficiently. Before we go any further I have to point out that this will be a general C programming tutorial. By that I mean that the programs we will produce will run on any platform using an ANSI C compatible compiler. For this tutorial I will be using the Prospero C compiler (given away free with Atari ST Review issue 17) on a bog standard Falcon 030 with 14Mb of RAM. I am using this compiler as it will run on any Atari TOS based machine, is ANSI compatible and easy to use. As I said this is a general C programming tutorial and we will not be going into programming GEM, therefore all programs should be compiled with a .TOS extender and not a .PRG exetender. If you find the program has compiled with a .PRG extender just use 'Show Information' from the desktop and change it to .TOS. A Short History Of Programming And The C language. Before going any further we will take a short look at the history of programming languages. When computers were first invented, during World War II, they were huge and incredibly complex machines, which filled whole rooms. To program these machines required highly skilled people with a detailed knowledge of how the computers worked and used obscure symbols relating to each machine operation. To help make the programming of computers simpler Assembly Language was developed. This language used short mnemonics to represent each machine operation e.g. LDA (Load Accumulator). As can be seen the people programming still needed a detailed knowledge of how the machines worked and each computer used an entirely different language depending on the manufacturer. During the fifties, as the use of computers became more widespread, especially amongst the business and scientific communities, more standardised languages were needed. With backing from the U.S. Government two languages emerged these were COBOL (COmmon Business Oriented Language) and FORTRAN (FORmula TRANslation). The first language used English like words which made it fairly easy to understand and was geared towards businesses where it was used for programs wuch as payrolls, stock accounts, etc. where a lot of file access was needed. FORTRAN was geared toward the scientific and engineering communities, and made it easy to translate comples formulae into fairly short program statements. Both these languages are still used today, especially COBOL. During the sixties many programming languages emerged, many of which are still in use today, and many attempts were made at producing a standard operating system. In America, Bell Labs had been involved in one of the attempts to produce a standard multi- user operating system call MULTICS. In the late sixties Bell withdrew from this project but one its computer scientists, Ken Thompson, had been developing programs, using Fortran, on this system. Thompson decided to produce his own operating system which he christened UNIX. As well as developing an operating system he developed a language for using on it called B, which he developed from from an earlier language called BCPL (Basic Combined Programming Language) developed by Martin Richards, which in turn had been developed from an earlier language called CPL (Common Programming Language) developed at the London and Oxford Universities. In 1969 Thompson was joined by another Bell scientist called Dennis Ritchie, who helped Thompson develop his UNIX operating system and who took the bare-bones B programming Language and developed another language which he called C. In 1973 both the development of UNIX and C took a giant leap forward, Ritchie and Thompson re-wrote the UNIX kernel (system programs) in C. Before this the UNIX kernel had been coded in assembler, this meant to transfer it to other platforms (it was originally developed on a DEC PDP-11) it had to be re-coded. Once the kernel had been written in C, to transfer it across to other systems all that was needed was a C compiler for the target platform. As UNIX was virtually free it soon spread throughout the universities and colleges and became one the most widespread operating sytems in use. Because C was the preferred programming language for developing software on UNIX it soon became one the fastest growing languages being used. As personal micro-computers became more widespread at home and in business, and also more powerful, C soon spread across various platforms and was no longer confined to the UNIX operating system. As the C language was designed by, and for use by, computer programmers it soon became the most popular, multi-purpose programming language. The key features of C are * Operating System Portability * Highly Efficient Object Code * Ease Of Access To Hardware Features * Support Of Structured Programming * Separate Compilation Of Modules * Standard Library Functions In part 2 I will cover each of features in detail and what they mean. For the meantime type in and compile the following program. How you do this depends on the compiler you are using. I will explain the program in detail next month. #include void main(void) { char ch; printf("HELLO WORLD!!!!\n\n"); printf("Press any key to continue\n"); ch = getchar(); }