This book is devoted to practical C programming. C is currently the premier language for software developers. Thats because its widely distributed and standard. Newer languages are available, such as C++, but these are still evolving. C is still the language of choice for robust, portable programming.
This book emphasizes the skills you will need to do real-world programming. It teaches you not only the mechanics of the C language, but the entire life cycle of a C program as well (including the programs conception, design, code, methods, debugging, release, documentation, maintenance, and revision).
Good style is emphasized. To create a good program you must do more than just type in code. It is an art in which writing and programming skills blend themselves together to form a masterpiece. True art can be created. A well-written program not only functions correctly, but is simple and easy to understand. Comments allow the programmer to include descriptive text inside the program. When clearly written, a commented program is highly prized.
A program should be as simple as possible. A programmer should avoid clever tricks. This book stresses simple, practical rules. For example, there are 15 operator precedence rules in C. These can be simplified into two rules:
Consider two programs. One was written by a clever programmer using all the tricks. The program contains no comments, but it works. The other program is well commented and nicely structured, but it doesnt work. Which program is more useful? In the long run, the broken one. It can be fixed. Although the clever program works now, sooner or later all programs have to be modified. The worst thing that you will ever have to do is to modify a cleverly written program.
This handbook is written for people with no previous programming experience or programmers who already know C and want to improve their style and reliability. You should have access to a computer and know how to use the basic functions such as a text editor and the filesystem.
Specific instructions are given for producing and running programs using the UNIX operating system with a generic cc compiler or the Free Software Foundations gcc compiler. For MS-DOS/Windows users, instructions are included for Borland C++, Turbo C++, and Microsoft Visual C++. (These compilers compile both C and C++ code.) The book also gives examples of using the programming utility make for automated program production.
Chapter by Chapter
gives a brief description of the C language and its use. This chapter includes some background on the history of the language.
explains the basic programming process and gives you enough information to write a very simple program.
discusses programming style. Commenting a program is covered, as well as writing clear and simple code.
introduces you to simple C statements. Basic variables and the assignment statement are covered in detail, along with arithmetic operators +, -, *, /, and %.
covers arrays and more complex variables. Shorthand operators such as ++ and %= are also described.
explains simple decision statements including if, else, and for. A discussion of == versus = is presented.
takes you through all the necessary steps to create a simple program from specification through release. Structured programming, fast prototyping, and debugging are also discussed.
describes additional control statements. Included are while, break, and continue. The switch statement is discussed in detail.
introduces local variables, functions, and parameters.
describes the C preprocessor, which gives the programmer tremendous flexibility in writing code. The chapter also provides the programmer with a tremendous number of ways to mess up. Simple rules that help keep the preprocessor from becoming a problem are described.
discusses the logical C operators that work on bits.
explains structures and other advanced types. The sizeof operator and the enum type are included.
introduces C pointer variables and shows some of their uses.
describes both buffered and unbuffered input/output. ASCII and binary files are discussed, and you are shown how to construct a simple file.
describes how to debug a program, as well as how to use an interactive debugger. You are shown not only how to debug a program, but also how to write a program so that it is easy to debug. This chapter also describes many optimization techniques for making your program run faster and more efficiently.
uses a simple decimal floating-point format to introduce you to the problems inherent in floating point, such as roundoff error, precision loss, overflow, and underflow.
describes advanced uses of pointers for constructing dynamic structures such as linked lists and trees.
shows how to split a program into several files and use modular programming techniques. The make utility is explained in more detail.
describes the old, pre-ANSI C language and associated compilers. Although such compilers are rare today, a lot of code was written for them and there are still a large number of programs out there that use the old syntax.
describes the problems that can occur when you port a program (move it from one machine to another).
describes the do/while statement, the , operator, and the ? and : operators.
details the steps necessary to take a complex program from conception to completion. Information-hiding and modular programming techniques are emphasized.
lists some programming adages that will help you construct good C programs.
lists the octal, hexadecimal, and decimal representations of the ASCII character set that is now in almost universal use.
lists the limits you can expect to come up against in handling numbers with various sizes of memory allocation.
lists those impossible-to-remember rules, to help you when you encounter code written by rude people who didnt use enough parentheses.
, illustrates the manipulation of floating-point (real) numbers, which did not receive complete attention in the rest of the book.