The introduction to On To C follows. Additional
information about this book, along with access to software, is available
How On To C Teaches You C
The purpose of this book is to help you learn the essentials of
C programming. In this section, you learn why you should
know C and how this book is organized.
Early versions of the Unix operating system were written in a language
named B, which was based, in part, on a language named
BCPL. The implementers of Unix then developed another, better
language, based on their experience with B. They decided to name
that new language C inasmuch as it
Today, just about all computers are organized around bits, bytes, and
collections of bytes. Instruction sets vary greatly, however.
Accordingly, C allows you to refer to bits, bytes, and collections of
bytes explicitly, but C does not allow you to specify computer-specific
instructions. Instead, your computer-independent, higher-level function
descriptions are translated for you into sequences of computer-specific
Assembler languages allow you to specify functions at the level of
computer-specific instructions, which operate on memory chunks of various
sizes. Thus, programs written in assembler languages are not
C, by contrast, allows you to specify sequences of computer-independent,
conceptual instructions, which operate on memory chunks of various sizes.
Thus, programs written in C are portable.
By encouraging you to think in terms of memory chunks, yet discouraging you
from thinking in terms of
computer-specific instructions, C provides a
sensible tradeoff, enabling you to write programs that are both fast and
portable. Accordingly, C is sometimes called a portable assembler
C has became
popular by virtue of
attractive characteristics, such as the following:
- C is easy to learn.
- C programs are fast.
- C programs are concise.
- C compilers---programs that translate C programs into
machine instructions---are usually fast and concise.
- C compilers and C programs run on all sorts of computers,
from small personal computers to huge supercomputers.
- Unix, a popular operating system, happens to be written in C.
There are two principal reasons to learn
Also, because C is so widely used, you often hear programmers debate the
merits of other languages in terms of their advantages and disadvantages
relative to C.
- C is often the right language to use in situations requiring
maximum program speed and minimum program size.
- The supply of powerful off-the-shelf C software modules,
both free and for sale, is huge.
Four principles determined this introductory book's organization and style:
- The book should get you up and running in the language quickly.
- The book should answer your basic questions explicitly.
- The book should encourage you to develop a personal library of
solutions to standard programming problems.
- The book should deepen your understanding of the art of good
To get you up and running in C quickly, the sections in this book
generally supply you with the most useful approach to each programming
need, be it to display characters on your screen, to define a new function,
or to read data from a file.
To answer your basic questions explicitly, this book is divided
into parts that generally focus on one issue, which is plainly
announced in the title of the section. Accordingly, you see
titles such as the following:
- How to Do Arithmetic
- How to Define Simple Functions
- How to Process Data from Files
- How to Create Structures and Objects
- How to Organize a Multiple-File Program
To encourage you to develop a personal library of solutions to standard
programming problems, this book introduces many useful,
productivity-increasing, general-purpose, templatelike patterns---sometimes
called cliches by experienced programmers---that you can fill in
to achieve particular-purpose goals.
Cliches are introduced, because learning to program involves more than
learning to use programming-language primitives, just as learning to
speak a human language involves more than learning to use vocabulary words.
To deepen your understanding of the art of good programming practice, this
book emphasizes the value of such ideas as data abstraction and
In this book, single-idea segments, analogous to slides, are arranged in
sections that are analogous to slide shows. The segments come in several
varieties: basic segments explain essential ideas; sidetrip
segments introduce interesting, but skippable, ideas; practice segments
provide opportunities to experiment with new ideas; and highlights
segments summarize important points.
Finally, the book develops a simple, yet realistic C program, which you
see in many versions as your understanding of the language increases. In
its ultimate version, the program reads data from a file containing
recent stock-market information, computes the average price per share and
number of shares traded, and predicts the next-day's price using a straight
line fitted to previous prices. The statistical flavor of the example is
meant to suggest the popularity of C as a language for implementing
- C is a programming language that encourages you
to think in terms of memory chunks of various sizes, but not in terms of
- C enjoys considerable popularity, because C is easy to
learn, C programs are fast, C programs are concise, C programs allow
you to think intimately in terms of bits and bytes but not in terms of
computer-specific instruction sets, C compilers are usually fast and
concise, C compilers and C programs run on all sorts of
computers, off-the-shelf C programs are widely available, and
Unix, a popular operating system, happens to be written in C.
- This book gets you up and running in C quickly; it
answers your basic questions explicitly; it equips you with program
patterns that you can adapt to your own purposes; and it deepens your
understanding of the art of good programming practice.