Chapter 1 Introduction to Computers, the Internet and the Web1
1.1 Introduction2
1.2 What Is a Computer?3
1.3 Computer Organization3
1.4 Early Operating Systems4
1.5 Personal, Distributed and Client Server Computing4
1.6 Machine Languages, Assembly Languages and High-Level Languages5
1.7 Fortran, COBOL, Pascal and Ada6
1.8 History of C6
1.9 C Standard Library7
1.10 C++8
1.11 Java8
1.12 BASIC, Visual Basic, Visual C++, Visual C# and .NET9
1.13 Key Software Trend: Object Technology9
1.14 Typical C Program Development Environment10
1.15 Hardware Trends12
1.16 History of the Internet12
1.17 History of the World Wide Web13
1.18 Notes About C and This Book13
1.19 Web Resources14
Chapter 2 Introduction to C Programming25
2.1 Introduction25
2.2 A Simple C Program: Printing a Line of Text26
2.3 Another Simple C Program: Adding Two Integers29
2.4 Memory Concepts32
2.5 Arithmetic in C33
2.6 Decision Making: Equality and Relational Operators35
Chapter 3 Structured Program Development in C48
3.1 Introduction48
3.2 Algorithms49
3.3 Pseudocode49
3.4 Control Structures50
3.5 The if Selection Statement51
3.6 The if...else Selection Statement52
3.7 The while Repetition Statement55
3.8 Formulating Algorithms Case Study 1: Counter-Controlled Repetition56
3.9 Formulating Algorithms with Top-Down, Stepwise Refinement Case Study 2: Sentinel-Controlled
Repetition57
3.10 Formulating Algorithms with Top-Down, Stepwise Refinement Case Study 3: Nested Control
Structures62
3.11 Assignment Operators65
3.12 Increment and Decrement Operators65
Chapter 4 C Program Control82
4.1 Introduction83
4.2 Repetition Essentials83
4.3 Counter-Controlled Repetition83
4.4 for Repetition Statement85
4.5 for Statement: Notes and Observations86
4.6 Examples Using the for Statement87
4.7 switch Multiple-Selection Statement90
4.8 do...while Repetition Statement94
4.9 break and continue Statements95
4.10 Logical Operators97
4.11 Confusing Equality == and Assignment = Operators99
4.12 Structured Programming Summary100
Chapter 5 C Functions115
5.1 Introduction116
5.2 Program Modules in C116
5.3 Math Library Functions117
5.4 Functions118
5.5 Function Definitions118
5.6 Function Prototypes121
5.7 Function Call Stack and Activation Records123
5.8 Headers123
5.9 Calling Functions: Call-by-Value and Call-by-Reference124
5.10 Random Number Generation124
5.11 Example: A Game of Chance128
5.12 Storage Classes131
5.13 Scope Rules132
5.14 Recursion135
5.15 Example Using Recursion: Fibonacci Series137
5.16 Recursion vs. Iteration140
Chapter 6 C Arrays156
6.1 Introduction156
6.2 Arrays157
6.3 Defining Arrays158
6.4 Array Examples158
6.5 Passing Arrays to Functions168
6.6 Sorting Arrays171
6.7 Case Study: Computing Mean, Median and Mode Using Arrays173
6.8 Searching Arrays176
6.9 Multiple-Subscripted Arrays180
Chapter 7 C Pointers200
7.1 Introduction200
7.2 Pointer Variable Definitions and Initialization201
7.3 Pointer Operators201
7.4 Passing Arguments to Functions by Reference203
7.5 Using the const Qualifier with Pointers206
7.6 Bubble Sort Using Call-by-Reference210
7.7 sizeof Operator213
7.8 Pointer Expressions and Pointer Arithmetic214
7.9 Relationship between Pointers and Arrays216
7.10 Arrays of Pointers219
7.11 Case Study: Card Shuffiing and Dealing Simulation220
7.12 Pointers to Functions224
Chapter 8 C Characters and Strings243
8.1 Introduction244
8.2 Fundamentals of Strings and Characters244
8.3 Character-Handling Library245
8.4 String-Conversion Functions249
8.5 Standard InputOutput Library Functions252
8.6 String-Manipulation Functions of the String- Handling Library255
8.7 Comparison Functions of the String-Handling Library257
8.8 Search Functions of the String-Handling Library258
8.9 Memory Functions of the String-Handling Library262
8.10 Other Functions of the String-Handling Library265
Chapter 9 C Formatted InputOutput277
9.1 Introduction277
9.2 Streams278
9.3 Formatting Output with printf 278
9.4 Printing Integers278
9.5 Printing Floating-Point Numbers279
9.6 Printing Strings and Characters281
9.7 Other Conversion Specifiers281
9.8 Printing with Field Widths and Precision282
9.9 Using Flags in the printf Format Control String284
9.10 Printing Literals and Escape Sequences286
9.11 Reading Formatted Input with scanf287
Chapter 10 C Structures, Unions, Bit Manipulations and Enumerations298
10.1 Introduction298
10.2 Structure Definitions299
10.3 Initializing Structures301
10.4 Accessing Members of Structures301
10.5 Using Structures with Functions302
10.6 typedef 302
10.7 Example: High-Performance Card Shuffling and Dealing Simulation303
10.8 Unions305
10.9 Bitwise Operators307
10.10 Bit Fields313
10.11 Enumeration Constants315
Chapter 11 C File Processing325
11.1 Introduction325
11.2 Data Hierarchy326
11.3 Files and Streams327
11.4 Creating a Sequential-Access File327
11.5 Reading Data from a Sequential-Access File331
11.6 Random-Access Files335
11.7 Creating a Random-Access File335
11.8 Writing Data Randomly to a Random-Access File337
11.9 Reading Data from a Random-Access File339
11.10 Case Study: Transaction-Processing Program340
Chapter 12 C Data Structures353
12.1 Introduction353
12.2 Self-Referential Structures354
12.3 Dynamic Memory Allocation355
12.4 Linked Lists355
12.5 Stacks362
12.6 Queues366
12.7 Trees370
Chapter 13 C Preprocessor394
13.1 Introduction394
13.2 #include Preprocessor Directive395
13.3 #define Preprocessor Directive: Symbolic Constants395
13.4 #define Preprocessor Directive: Macros395
13.5 Conditional Compilation397
13.6 #error and #pragma Preprocessor Directives398
13.7 # and ## Operators398
13.8 Line Numbers398
13.9 Predefined Symbolic Constants399
13.10 Assertions399
Chapter 14 Other C Topics403
14.1 Introduction403
14.2 Redirecting InputOutput on LinuxUNIX and Windows Systems404
14.3 Variable-Length Argument Lists404
14.4 Using Command-Line Arguments406
14.5 Notes on Compiling Multiple-Source-File Programs407
14.6 Program Termination with exit and atexit 408
14.7 volatile Type Qualifier409
14.8 Suffixes for Integer and Floating-Point Constants409
14.9 More on Files410
14.10 Signal Handling411
14.11 Dynamic Memory Allocation: Functions calloc and realloc 413
14.12 Unconditional Branching with goto 413
Chapter 15 Game Programming with the Allegro C Library419
15.1 Introduction420
15.2 Installing Allegro420
15.3 A Simple Allegro Program420
15.4 Simple Graphics: Importing Bitmaps and Blitting421
15.5 Animation with Double Buffering424
15.6 Importing and Playing Sounds429
15.7 Keyboard Input432
15.8 Fonts and Displaying Text436
15.9 Implementing the Game of Pong439
15.10 Timers in Alleg