| |
| |
About the Author | |
| |
| |
Acknowledgments | |
| |
| |
Introduction | |
| |
| |
| |
Programming in C | |
| |
| |
Creating C Programs | |
| |
| |
Editing | |
| |
| |
Compiling | |
| |
| |
Linking | |
| |
| |
Executing | |
| |
| |
Creating Your First Program | |
| |
| |
Editing Your First Program | |
| |
| |
Dealing with Errors | |
| |
| |
Dissecting a Simple Program | |
| |
| |
Comments | |
| |
| |
Preprocessing Directives | |
| |
| |
Defining the main() Function | |
| |
| |
Keywords | |
| |
| |
The Body of a Function | |
| |
| |
Outputting Information | |
| |
| |
Arguments | |
| |
| |
Control Characters | |
| |
| |
Developing Programs in C | |
| |
| |
Understanding the Problem | |
| |
| |
Detailed Design | |
| |
| |
Implementation | |
| |
| |
Testing | |
| |
| |
Functions and Modular Programming | |
| |
| |
Common Mistakes | |
| |
| |
Points to Remember | |
| |
| |
Summary | |
| |
| |
Exercises | |
| |
| |
| |
First Steps in Programming | |
| |
| |
Memory in Your Computer | |
| |
| |
What Is a Variable? | |
| |
| |
Variables That Store Numbers | |
| |
| |
Integer Variables | |
| |
| |
Naming Variables | |
| |
| |
Using Variables | |
| |
| |
Initializing Variables | |
| |
| |
Arithmetic Statements | |
| |
| |
Variables and Memory | |
| |
| |
Integer Variable Types | |
| |
| |
Unsigned Integer Types | |
| |
| |
Using Integer Types | |
| |
| |
Specifying Integer Constants | |
| |
| |
Floating-Point Values | |
| |
| |
Floating-Point Variables | |
| |
| |
Division Using Floating-Point Values | |
| |
| |
Controlling the Number of Decimal Places | |
| |
| |
Controlling the Output Field Width | |
| |
| |
More Complicated Expressions | |
| |
| |
Defining Constants | |
| |
| |
Knowing Your Limitations | |
| |
| |
Introducing the size of Operator | |
| |
| |
Choosing the Correct Type for the Job | |
| |
| |
Explicit Type Conversion | |
| |
| |
Automatic Conversion | |
| |
| |
Rules for Implicit Conversions | |
| |
| |
Implicit Conversions in Assignment Statements | |
| |
| |
More Numeric Data Types | |
| |
| |
The Character Type | |
| |
| |
Character Input and Character Output | |
| |
| |
The Wide Character Type | |
| |
| |
Enumerations | |
| |
| |
Variables to Store Boolean Values | |
| |
| |
The Complex Number Types | |
| |
| |
The op= Form of Assignment | |
| |
| |
Mathematical Functions | |
| |
| |
Designing a Program | |
| |
| |
The Problem | |
| |
| |
The Analysis | |
| |
| |
The Solution | |
| |
| |
Summary | |
| |
| |
Exercises | |
| |
| |
| |
Making Decisions | |
| |
| |
The Decision-Making Process | |
| |
| |
Arithmetic Comparisons | |
| |
| |
Expressions Involving Relational Operators | |
| |
| |
The Basic if Statement | |
| |
| |
Extending the if Statement: if-else | |
| |
| |
Using Blocks of Code in if Statements | |
| |
| |
Nested if Statements | |
| |
| |
More Relational Operators | |
| |
| |
Logical Operators | |
| |
| |
The Conditional Operator | |
| |
| |
Operator Precedence: Who Goes First? | |
| |
| |
Multiple-Choice Questions | |
| |
| |
Using else-if Statements for Multiple Choices | |
| |
| |
The switch Statement | |
| |
| |
The goto Statement | |
| |
| |
Bitwise Operators | |
| |
| |
The op= Use of Bitwise Operators | |
| |
| |
Using Bitwise Operators | |
| |
| |
Designing a Program | |
| |
| |
The Problem | |
| |
| |
The Analysis | |
| |
| |
The Solution | |
| |
| |
Summary | |
| |
| |
Exercises | |
| |
| |
| |
Loops | |
| |
| |
How Loops Work | |
| |
| |
Introducing the Increment and Decrement Operators | |
| |
| |
The for Loop | |
| |
| |
General Syntax of the for Loop | |
| |
| |
More on the Increment and Decrement Operators | |
| |
| |
The Increment Operator | |
| |
| |
The Prefix and Postfix Forms of the Increment Operator | |
| |
| |
The Decrement Operator | |
| |
| |
The for Loop Revisited | |
| |
| |
Modifying the for Loop Variable | |
| |
| |
A for Loop with No Parameters | |
| |
| |
The break Statement in a Loop | |
| |
| |
Limiting Input Using a for Loop | |
| |
| |
Generating Pseudo-Random Integers | |
| |
| |
More for Loop Control Options | |
| |
| |
Floating-Point Loop Control Variables | |
| |
| |
The while Loop | |
| |
| |
Nested Loops | |
| |
| |
Nested Loops and the goto Statement | |
| |
| |
The do-while Loop | |
| |
| |
The continue Statement | |
| |
| |
Designing a Program | |
| |
| |
The Problem | |
| |
| |
The Analysis | |
| |
| |
The Solution | |
| |
| |
Summary | |
| |
| |
Exercises | |
| |
| |
| |
Arrays | |
| |
| |
An Introduction to Arrays | |
| |
| |
Programming Without Arrays | |
| |
| |
What Is an Array? | |
| |
| |
Using Arrays | |
| |
| |
A Reminder About Memory | |
| |
| |
Arrays and Addresses | |
| |
| |
Initializing an Array | |
| |
| |
Finding the Size of an Array | |
| |
| |
Multidimensional Arrays | |
| |
| |
Initializing Multidimensional Arrays | |
| |
| |
Designing a Program | |
| |
| |
The Problem | |
| |
| |
The Analysis | |
| |
| |
The Solution | |
| |
| |
Summary | |
| |
| |
Exercises | |
| |
| |
| |
Applications with Strings and Text | |
| |
| |
What Is a String? | |
| |
| |
String- and Text-Handling Methods | |
| |
| |
Operations with Strings | |
| |
| |
Appending a String | |
| |
| |
Arrays of Strings | |
| |
| |
String Library Functions | |
| |
| |
Copying Strings Using a Library Function | |
| |
| |
Determining String Length Using a Library Function | |
| |
| |
Joining Strings Using a Library Function | |
| |
| |
Comparing Strings | |
| |
| |
Searching a String | |
| |
| |
Analyzing and Transforming Strings | |
| |
| |
Converting Characters | |
| |
| |
Converting Strings to Numerical Values | |
| |
| |
Working with Wide Character Strings | |
| |
| |
Operations on Wide Character Strings | |
| |
| |
Testing and Converting Wide Characters | |
| |
| |
Designing a Program | |
| |
| |
The Problem | |
| |
| |
The Analysis | |
| |
| |
The Solution | |
| |
| |
Summary | |
| |
| |
Exercises | |
| |
| |
| |
Pointers | |
| |
| |
A First Look at Pointers | |
| |
| |
Declaring Pointers | |
| |
| |
Accessing a Value Through a Pointer | |
| |
| |
Using Pointers | |
| |
| |
Pointers to Constants | |
| |
| |
Constant Pointers | |
| |
| |
Naming Pointers | |
| |
| |
Arrays and Pointers | |
| |
| |
Multidimensional Arrays | |
| |
| |
Multidimensional Arrays and Pointers | |
| |
| |
Accessing Array Elements | |
| |
| |
Using Memory As You Go | |
| |
| |
Dynamic Memory Allocation: The malloc() Function | |
| |
| |
Memory Allocation with the calloc() Function | |
| |
| |
Releasing Dynamically Allocated Memory | |
| |
| |
Reallocating Memory | |
| |
| |
Handling Strings Using Pointers | |
| |
| |
String Input with More Control | |
| |
| |
Using Arrays of Pointers | |
| |
| |
Designing a Program | |
| |
| |
The Problem | |
| |
| |
The Analysis | |
| |
| |
The Solution | |
| |
| |
Summary | |
| |
| |
Exercises | |
| |
| |
| |
Structuring Your Programs | |
| |
| |
Program Structure | |
| |
| |
Variable Scope and Lifetime | |
| |
| |
Variable Scope and Functions | |
| |
| |
Functions | |
| |
| |
Defining a Function | |
| |
| |
The return Statement | |
| |
| |
The Pass-By-Value Mechanism | |
| |
| |
Function Declarations | |
| |
| |
Pointers As Arguments and Return Values | |
| |
| |
const Parameters | |
| |
| |
Returning Pointer Values from a Function | |
| |
| |
Incrementing Pointers in a Function | |
| |
| |
Summary | |
| |
| |
Exercises | |
| |
| |
| |
More on Functions | |
| |
| |
Pointers to Functions | |
| |
| |
Declaring a Pointer to a Function | |
| |
| |
Calling a Function Through a Function Pointer | |
| |
| |
Arrays of Pointers to Functions | |
| |
| |
Pointers to Functions As Arguments | |
| |
| |
Variables in Functions | |
| |
| |
Static Variables: Keeping Track Within a Function | |
| |
| |
Sharing Variables Between Functions | |
| |
| |
Functions That Call Themselves: Recursion | |
| |
| |
Functions with a Variable Number of Arguments | |
| |
| |
Copying a va_list | |
| |
| |
Basic Rules for Variable-Length Argument Lists | |
| |
| |
The main() Function | |
| |
| |
Ending a Program | |
| |
| |
Libraries of Functions: Header Files | |
| |
| |
Enhancing Performance | |
| |
| |
Declaring Functions inline | |
| |
| |
Using the restrict Keyword | |
| |
| |
Designing a Program | |
| |
| |
The Problem | |
| |
| |
The Analysis | |
| |
| |
The Solution | |
| |
| |
Summary | |
| |
| |
Exercises | |
| |
| |
| |
Essential Input and Output Operations | |
| |
| |
Input and Output Streams | |
| |
| |
Standard Streams | |
| |
| |
Input from the Keyboard | |
| |
| |
Formatted Keyboard Input | |
| |
| |
Input Format Control Strings | |
| |
| |
Characters in the Input Format String | |
| |
| |
Variations on Floating-Point Input | |
| |
| |
Reading Hexadecimal and Octal Values | |
| |
| |
Reading Characters Using scanf() | |
| |
| |
Pitfalls with scanf() | |
| |
| |
String Input from the Keyboard | |
| |
| |
Unformatted Input from the Keyboard | |
| |
| |
Output to the Screen | |
| |
| |
Formatted Output to the Screen Using printf() | |
| |
| |
Escape Sequences | |
| |
| |
Integer Output | |
| |
| |
Outputting Floating-Point Values | |
| |
| |
Character Output | |
| |
| |
Other Output Functions | |
| |
| |
Unformatted Output to the Screen | |
| |
| |
Formatted Output to an Array | |
| |
| |
Formatted Input from an Array | |
| |
| |
Sending Output to the Printer | |
| |
| |
Summary | |
| |
| |
Exercises | |
| |
| |
| |
Structuring Data | |
| |
| |
Data Structures: Using struct | |
| |
| |
Defining Structure Types and Structure Variables | |
| |
| |
Accessing Structure Members | |
| |
| |
Unnamed Structures | |
| |
| |
Arrays of Structures | |
| |
| |
Structures in Expressions | |
| |
| |
Pointers to Structures | |
| |
| |
Dynamic Memory Allocation for Structures | |
| |
| |
More on Structure Members | |
| |
| |
Structures As Members of a Structure | |
| |
| |
Declaring a Structure Within a Structure | |
| |
| |
Pointers to Structures As Structure Members | |
| |
| |
Doubly Linked Lists | |
| |
| |
Bit-Fields in a Structure | |
| |
| |
Structures and Functions | |
| |
| |
Structures As Arguments to Functions | |
| |
| |
Pointers to Structures As Function Arguments | |
| |
| |
A Structure As a Function Return Value | |
| |
| |
An Exercise in Program Modification | |
| |
| |
Binary Trees | |
| |
| |
Sharing Memory | |
| |
| |
Unions | |
| |
| |
Pointers to Unions | |
| |
| |
Initializing Unions | |
| |
| |
Structures As Union Members | |
| |
| |
Defining Your Own Data Types | |
| |
| |
Structures and the typedef Facility | |
| |
| |
Simplifying Code Using typedef | |
| |
| |
Designing a Program | |
| |
| |
The Problem | |
| |
| |
The Analysis | |
| |
| |
The Solution | |
| |
| |
Summary | |
| |
| |
Exercises | |
| |
| |
| |
Working with Files | |
| |
| |
The Concept of a File | |
| |
| |
Positions in a File | |
| |
| |
File Streams | |
| |
| |
Accessing Files | |
| |
| |
Opening a File | |
| |
| |
Renaming a File | |
| |
| |
Closing a File | |
| |
| |
Deleting a File | |
| |
| |
Writing to a Text File | |
| |
| |
Reading from a Text File | |
| |
| |
Writing Strings to a Text File | |
| |
| |
Reading Strings from a Text File | |
| |
| |
Formatted File Input and Output | |
| |
| |
Formatted Output to a File | |
| |
| |
Formatted Input from a File | |
| |
| |
Dealing with Errors | |
| |
| |
Further Text File Operation Modes | |
| |
| |
Binary File Input and Output | |
| |
| |
Specifying Binary Mode | |
| |
| |
Writing a Binary File | |
| |
| |
Reading a Binary File | |
| |
| |
Moving Around in a File | |
| |
| |
File Positioning Operations | |
| |
| |
Finding Out Where You Are | |
| |
| |
Setting a Position in a File | |
| |
| |
Using Temporary Work Files | |
| |
| |
Creating a Temporary Work File | |
| |
| |
Creating a Unique File Name | |
| |
| |
Updating Binary Files | |
| |
| |
Changing the File Contents | |
| |
| |
Reading a Record from the Keyboard | |
| |
| |
Writing a Record to a File | |
| |
| |
Reading a Record from a File | |
| |
| |
Writing a File | |
| |
| |
Listing the File Contents | |
| |
| |
Updating the Existing File Contents | |
| |
| |
File Open Modes Summary | |
| |
| |
Designing a Program | |
| |
| |
The Problem | |
| |
| |
The Analysis | |
| |
| |
The Solution | |
| |
| |
Summary | |
| |
| |
Exercises | |
| |
| |
| |
Supporting Facilities | |
| |
| |
Preprocessing | |
| |
| |
Including Header Files in Your Programs | |
| |
| |
External Variables and Functions | |
| |
| |
Substitutions in Your Program Source Code | |
| |
| |
Macro Substitutions | |
| |
| |
Macros That Look Like Functions | |
| |
| |
Preprocessor Directives on Multiple Lines | |
| |
| |
Strings As Macro Arguments | |
| |
| |
Joining Two Results of a Macro Expansion | |
| |
| |
Logical Preprocessor Directives | |
| |
| |
Conditional Compilation | |
| |
| |
Directives Testing for Specific Values | |
| |
| |
Multiple-Choice Selections | |
| |
| |
Standard Preprocessing Macros | |
| |
| |
Debugging Methods | |
| |
| |
Integrated Debuggers | |
| |
| |
The Preprocessor in Debugging | |
| |
| |
Using the assert() Macro | |
| |
| |
Additional Library Functions | |
| |
| |
The Date and Time Function Library | |
| |
| |
Getting the Date | |
| |
| |
Summary | |
| |
| |
Exercises | |
| |
| |
| |
Computer Arithmetic | |
| |
| |
Binary Numbers | |
| |
| |
Hexadecimal Numbers | |
| |
| |
Negative Binary Numbers | |
| |
| |
Big-Endian and Little-Endian Systems | |
| |
| |
Floating-Point Numbers | |
| |
| |
| |
ASCII Character Code Definitions | |
| |
| |
| |
Reserved Words in C | |
| |
| |
| |
Input and Output Format Specifications | |
| |
| |
Output Format Specifications | |
| |
| |
Input Format Specifications | |
| |
| |
Index | |