0
Practical C Programming, 3rd Edition
By Steve Oualline
3rd Edition August 1997
ISBN: 1-56592-306-5
This new edition of "Practical C Programming" teaches users not only the mechanics or
programming, but also how to create programs that are easy to read, maintain, and
debug. It features more extensive examples and an introduction to graphical
development environments. Programs conform to ANSI C.
TEAM FLY PRESENTS
1
Table of Contents
Preface
How This Book is Organized
Chapter by Chapter
Notes on the Third Edition
Font Conventions
Variables and Storage TEAM FLY PRESENTS
2
Variable Declarations
Integers
Assignment Statements
printf Function
Floating Point
Floating Point Versus Integer Divide
Characters
Answers
Programming Exercises
5. Arrays, Qualifiers, and Reading Numbers
Arrays
Strings
Reading Strings
Multidimensional Arrays
Reading Numbers
Initializing Variables
Types of Integers
Types of Floats
Constant Declarations
Hexadecimal and Octal Constants
Operators for Performing Shortcuts
Side Effects
++x or x++
Revisions
Electronic Archaeology
Marking Up the Program
Using the Debugger
Text Editor as a Browser
Add Comments
Programming Exercises
II. Simple Programming
8. More Control Statements
for Statement
switch Statement
switch, break, and continue
Answers
Programming Exercises
9. Variable Scope and Functions
Scope and Class
Functions
Functions with No Parameters
Structured Programming
Recursion
Answers
Programming Exercises
10. C Preprocessor
#define Statement
Conditional Compilation
include Files
Parameterized Macros
Advanced Features
Summary
Answers
const Pointers
Pointers and Arrays
How Not to Use Pointers
Using Pointers to Split a String
Pointers and Structures
Command-Line Arguments
Programming Exercises
Answers
14. File Input/Output
Conversion Routines
Binary and ASCII Files
The End-of-Line Puzzle
Binary I/O
Buffering Problems
Unbuffered I/O
Designing File Formats
Answers
Programming Exercises
15. Debugging and Optimization
Debugging
Interactive Debuggers
TEAM FLY PRESENTS
5
Debugging a Binary Search
Runtime Errors
The Confessional Method of Debugging
18. Modular Programming
Modules
Public and Private
The extern Modifier
Headers
The Body of the Module
A Program to Use Infinite Arrays TEAM FLY PRESENTS
6
The Makefile for Multiple Files
Using the Infinite Array
Dividing a Task into Modules
Module Division Example: Text Editor
Compiler
Spreadsheet
Module Design Guidelines
Programming Exercises
19. Ancient Compilers
K&R-Style Functions
Library Changes
Missing Features
Free/Malloc Changes
lint
Answers
20. Portability Problems
Modularity
Revisions
A Final Warning
Program Files
Programming Exercises
23. Programming Adages
General
Design
Declarations
switch Statement
Preprocessor
Style
Compiling
Final Note
Answer
IV. Other Language Features
A. ASCII Table
B. Ranges and Parameter Passing Conversions
C. Operator Precedence Rules
D. A Program to Compute a Sine Using a Power Series
Glossary
Index
TEAM FLY PRESENTS
8
Preface
This book is devoted to practical C programming. C is currently the
experience or programmers who already know C and want to improve
their style and reliability. You should have access to a computer and
TEAM FLY PRESENTS
9
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 Foundation's 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.
How This Book is Organized
You must crawl before you walk. In Part I we teach you how to crawl.
These chapters enable you to write very simple programs. We start
with the mechanics of programming and programming style. Next,
you learn how to use variables and very simple decision and control
statements. In Chapter 7, we take you on a complete tour of the
software life cycle to show you how real programs are created.
Part II describes all of the other simple statements and operators that
are used in programming. You'll also learn how to organize these
statements into simple functions.
In Part III we take our basic declarations and statements and learn
how they can be used in the construction of advanced types such as
structures, unions, and classes. We'll also introduce the concept of
tremendous number of ways to mess up. Simple rules that help keep the
preprocessor from becoming a problem are described.
Chapter 11 discusses the logical C operators that work on bits.
Chapter 12 explains structures and other advanced types. The sizeof operator and
the enum type are included.
Chapter 13 introduces C pointer variables and shows some of their uses.
Chapter 14 describes both buffered and unbuffered input/output. ASCII and binary
files are discussed, and you are shown how to construct a simple file.
Chapter 15 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.
Chapter 16 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.
Chapter 17 describes advanced uses of pointers for constructing dynamic structures
such as linked lists and trees.
TEAM FLY PRESENTS
11
Chapter 18 shows how to split a program into several files and use modular
programming techniques. The make utility is explained in more detail.
Chapter 19 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.
Chapter 20 describes the problems that can occur when you port a program (move
it from one machine to another).
TEAM FLY PRESENTS