| C: Step-by-Step
|
| Mitchell Waite, Stephen Prata
|
| SAMS
|
| 1989 |
| 0-672-22651-0
|
| $29.95 (US)
|
Although this is one of my older books, it still serves me as a good reference. This book
really takes its time in explaining things out and taking a very moderate pace. It only gets
as far as using structures, but it does cover bit manipulation. It covers straight C but doesn't
cover any subjects concerned with C++. This makes it ideal for those that want to get a grasp
of C without having to be bombarded with the C++ additions. This book has a LOT of example code
that illistrate how to use the subject at hand. At the end of each chapter are Review Questions and
programming exercises that test your complete understanding of the chapter. A very complete book.
It's also super for newbies!

1 C and Programming
Contents 1
Objectives 1
1.1 C History 2
1.2 C Virutes 2
Design Features 2
Efficiency 3
Portablity 3
Power and Flexibility 3
Programmer Orientation 3
Potentially Disadvantageous Disvirtues (Faults) 4
1.3 C Trends 4
1.4 Using C: Seven Steps 4
Step1: Define the program Objetives 5
Step 2: Design the Program 5
Step 3: Write the Code 6
Step 4: Compile the Code 7
Step 5: Run the Program 7
Step 6: Test and Debug the Program 7
Step 7: Maintain and Modify the Program 8
Commentary for Beginners 9
1.5 A Design Example 10
Definingthe Program Objectives 10
Designing the Program 10
Writing the Program 11
Structed Programming 12
1.6 Programming Mechanics 12
Source Code Files 12
Object Code Files, Executable Files, and Libraires 13
Preparing a C Program on a UNIX System 14
Preparing a C Program on an IBM PC (Microsoft C) 16
Preparing a C Program on an IBM PC(Turbo C and Quick C) 17
Why Compile? 18
1.7 Language Standards 19
1.8 Some Typographic Onventions 19
Typeface 19
Screen Output 20
Input and Output Devices 20
1.9 Summary 20
Review Questions 21
Programming Exercises 21
2 Introducing C
Contents 23
Objectives 23
2.1 A Simple Sample of C 24
2.2 The Explanation 25
Pass1: Quick Synopsis 25
Pass2: Details 27
2.3 The Structure of a Simple Program 32
2.4 Tips on Making Your Programs Readable 32
2.5 Taking Another Step 34
Documentation 34
Multiple Declarations 34
Multiplication 35
Printing Multiple Values 35
2.6 Multiple Functions 35
2.7 Debugginhg 36
Syntax Errors 36
Semantic Errors 37
Program State 39
2.8 Keywords 39
2.9 Summary 39
Review Questions 40
Programming Exercises 42
3 Data and C
Contents 45
Objectives 45
3.1 A Sample Program 46
What's New in This Program 47
3.2 Data: variables and Constandts 48
3.3 Data: Data YTypes 49
Interger versus Floating point Types 49
The Integer 49
The Floating point Number 49
3.4 C Data Types 52
The int Type 52
Other Integer tyhpes 55
Using Characters : Type char 59
Types float and double 63
Other Types 66
Type Sizes 67
3.5 Using Data Types 69
3.6 I/O Arguments and Pitfalls 70
3.7 One More Example 71
What Happens 71
A Possible Problem 72
3.8 Syummary 73
Review Questions 74
Programming Exercises 75
4 Character Stings and Formatted Input/Output
Contents 77
Objectives 77
4.1 Introductory Program 78
4.2 Character Strings, An Introduction 79
Type char Arrays and the Null Character 79
Using Strings 80
String Length strlen() 81
4.3 Constants and the C Preprocessor 83
Using #define and #include Together 86
C, A master of Disguise: Creating Aliases 87
4.4 Exploring and Exploiting printf() and scanf() 88
printf() 89
Using printf() 89
Conversion Specification Modifiers for printf() 92
The Meaning of Conversion 96
Using scanf() 102
The scanf() View of Iput 104
The * Modifier with prinf() and scanf() 105
4.5 Usage Tips 107
4.6 Summary 108
Review Questions 109
Programming Exercises 111
5 Operators, Expressions, and Statements
Contents 113
Objectives 113
5.1 Introducing Loops 114
5.2 Fundamental Operators 116
Assignment Operator: = 116
Addition Operator: + 118
Subtraction Operator: - 118
Sign Operators :- and + 118
Multiplication Operator: * 119
Division Operator: / 121
Operator Precedence 122
Precedence and the Order of Evaluation 124
5.3 Some Additional Operators 126
The sizeof Operator 126
Modulus Operator: % 126
The Incrementing Operator: ++ 128
The Derementing Operator: -- 131
Precedence 132
Don't Be Too Clever 133
5.4 Expressions and Staements 134
Expressions 134
Statments 135
Compound Statements (Blocks) 136
5.5 Type Conversions 138
The Cast Operator 141
5.6 Function Arguments and Type Conversions 142
5.7 An Example Program 143
5.8 Summary 145
Review Questions 146
Programming Exercises 149
6 C Control Statments: Looping
Contents 151
Objetives 151
6.1 An Intitial Example 152
Program Comments 153
C Styel Reading Loop 154
6.2 The while Statement 155
Terminating a while Loop 155
When a Loop Terminates 156
while : An Entry Contiditon Loop 157
Syntax points 157
6.3 WhichIs Bigger: Using Relational Operators and Expressions 159
What Is Truth 160
So What Else is Ture 161
Troubles with Truth 162
Precedence of Relational Operators 164
6.4 Indefinite Loops an Counting Loops 166
The for Loop 167
Using for for Flexibility 168
The Comma Operator 174
Zeno Meets the for Loop 176
6.6 An Exit-condition Loop: do while 178
6.7 Which Loop 180
6.8 Nested Loops 181
Discussion 182
A Nested Variation 182
6.9 Arrays 183
Using a for Loop with an Array 184
6.10 A Loop Example using a Function Return Value 186
Program Discussion 188
Using Functions with Return Values 189
6.11 Summary 190
Review Questions 190
Programming Exercises 194
7 C Control Statements: Branching and Jumps
contents 197
Objectives 197
7.1 The if Statement 198
if Basics 199
7.2 Adding else tothe if Statement 200
Another Example: introducing getchar() and puchar() 201
Multiple choice: else if 204
Pairing elses with ifs 207
More Nested ifs 207
7.3 Let's Get Logical 212
Precedence 213
Order of Evaluation 214
7.4 A Word Count Program 215
7.5 The Conditional Operator: ? 217
7.6 Multiple choice: switch and break 220
Using the switch statement 221
Reading Only the First Character of a Line 223
Multiple Lables 223
switch and if else 225
7.7 Other Control Statments: break, continue, goto 225
The break Statment 225
the continue Statement 226
The goto Statement 228
7.8 Summary 232
Review Questions 232
Programming Exercises 236
8 Character Input/ Output and Redirection
Contents 239
Objectives 239
8.1 Single-Character I/O getchar() and putchar() 240
8.2 Buffers 241
8.3 Terminating Keyboard Input 242
Files, Streams, and Keyboard Input 242
The End of File 244
8.4 Redirection and Files 246
Unix and DOs Redirection 247
Comment 250
8.5 A Graphic Example 250
8.6 Creating a More Friendly User Interface 252
Working with Buffered Input 252
Mixing Numeric and Character Input 255
8.7 Character Sketches 258
Analyzing the Program 260
8.8 Menu Browsing 263
Tasks 263
Toward a Smoother Execution 263
Mixing Character and Numeric Input 265
8.9 Summary 268
Review Questions 269
Programming Exercises 270
9 Functions
Contents 273
Objectives 273
9.1 Review 274
Creating and Using a Simple Function 275
Function Arguments 278
Defining a Function with an Argument: Formal Arguments 279
Calling a Function with an Argument: Actual Arguments 280
The Black-Box Viewpoint 281
Returning a Value from a Function with return 281
Function Types 283
9.2 ANSI C Function Prototyping 285
The Problem 285
The ANSI Solution 286
No Arguments and Unspecified Arguments 287
ANSI-Style Function Definitions 288
9.3 Finding Addresses: The & Operator 288
9.4 Altering Variables in the Calling Program 290
9.5 Pointers: A First Look 292
The Indirection Operator: * 292
Declaring Pointers 293
Using Pointers to Communicate Between Functions 294
9.6 Recursion 297
Recursion Revealed 297
Recursion Fundamentals 299
Tail Recursion 300
Recursion and Reversal 201
9.7 All C Functions are Created Equal 304
9.8 Compiling Programs with Two or More Functions 305
UNIX 306
Microsoft C 4.0-5.1 306
QuickC 306
TurboC 306
Using Header Files 306
9.9 Summary 310
Review Questions 310
Programming Exercises 311
10 Arrays and Pointers
Contents 313
Objectives 313
10.1 Arrays 314
Initialization and Storage Classes 314
More Array Initialization 316
Asigning Array Values 319
10.2 Pointers to Arrays 320
10.3 Functions, Arrays, and Pointers 323
Array Names as Arguments 324
Using Pointer Arguments 325
Pointers and Arrays: A Comment 326
10.4 Pointer Operations 327
10.5 Another Example 329
10.6 Multidimensional Arrays 330
Computation Scheme 333
Initializing a Two-Dimensional Array 333
10.7 Pointers and Multidimensional Arrays 334
Functions and Multidimensional Arrays 337
10.8 Planning a Program 342
General Plan 342
The read_array() function 343
The show_array() function 344
the mean() function 345
The Result 346
10.9 Summary 347
Review Questions 348
Programming Exercises 350
11 Character Strings and String Functions
Contents 355
Objectives 353
11.1 Defining Strings withing a Program 355
Character String Constants 355
Character String Arrays and Initialization 356
Array Versus Pointer 357
Specifying Storage Explicitly 359
Arrays of Character Strings 360
Pointer and Strings 361
11.2 String Input 362
Creating Space 362
The gets() Function 362
the scanf() Function 365
11.3 String Output 366
The puts() Function 367
The printf() Function 367
11.4 The Do-It-Yourself Option 368
11.5 String Functions 370
The strlen() Function 370
The strcat() Function 371
The strcmp() Function 373
The strcpy () Function 376
The sprintf() Function 377
Other String Functions 379
11.6 A String Example: Sorting Strings 379
Sorting 381
11.7 The ctype.h Character Functions 382
11.8 Command-Line Arugments 383
Command-Line Arguments in Inegrated Environments 385
Command-Line Options 385
11.9 String-to-Number Conversions 386
11.10 Summary 388
Review Questions 389
Programming Exercises 392
12 File Input/Output
Contents 395
Objectives 395
12.1 Communcating with Files 396
What Is a File 396
Levels of IO 397
Standard Files 398
12.2 Low-Level-I/O 398
Berkely (BSD) UNIX 400
MS-DOS 400
Standard File Descriptors 401
Using a Bufer 401
Performance Considerations 402
Commentary 403
12.3 Standard I/O 403
The fopen() Function 404
The getc() and putc() Functions 405
The fclose() Funciton 405
Standard Files 406
12.4 A Simple File-Condensing Program 406
12.5 FileIP: fprintf(),fscanf(),fgets(),and fputs() 408
The fprintf() and fscanf() Functions 408
The fgets() and fputs() Functions 409
12.6 Randome Access: fseek() and ftell() 411
How fseek () and ftell() work 412
Binary Mode Versus Test Mode 413
Portability 414
12.7 Using Random Access in a Text Mode 414
12.8 Behind the Scenes with Standard I/O 416
Comment 417
12.9 Other Standard I/O Functions 417
int ungetc(intc,FILE*fp() 417
int fflush(FILE*) 418
int setvbuf(FILE*,char*,int,size_t) 418
BinaryIO: fread() and fwrite() 418
size_t fwrite(void*,size_t,size_t,FILE*) 420
size_t fread(void*,size_t,size_t,FILE*) 420
int feof(FILE*) and int ferro(FILE*) 421
An Example 421
12.10 Summary 424
Review Questions 424
Programming Exercises 426
13 Storage Classes and Program Development
Contents 429
Objectives 429
13.1 Storage Classes and Scope 430
Automatic Variables 431
External Variables 432
Definitions and Declarations 434
Static Variables 435
External Static Variables 436
Muliple files 437
Scope and Functions 437
Register Variables 438
Scope Summary 438
Which Storage Class? 438
13.2 ANSI C Type Qualifiers 439
The const Type Qualifier 440
The volatile Type Qualifier 441
13.3 A Random Number Function 442
13.4 Roll 'Em 444
13.5 Sorting Numbers 447
Global Decisions 448
Reading In Numeric Data 449
Ending Input 449
Further Considerations 450
The getarray() Function 450
Explanation 451
The getint() Function 452
Sorting the Data 453
Printing the Data 455
Results 456
13.6 Another Example 456
Changing the Plan for main() 457
The fgetarray() Function 459
The fgetint() Function 460
The sort() Function 460
The print() Function 460
13.7 Summary 461
Review Questions 462
Programming Exercises 463
14 Structures and Other Data Forms
Contents 465
Objectives 465
14.1 Example Problem: Creating an Inventory of Books 466
14.2 Setting Up the Structure Template 467
14.3 Defining a Structure Variable 468
Initalizing a Structure 469
14.4 Gaining Access to Structure Members 470
14.5 Arrays of Structures 471
Declaring an Array of Structures 472
Identifying Members of a Structure Array 473
Program Details 474
14.6 Nested Structures 474
14.7 Pointers to Stuctures 476
Declaring and Intializing a Structure Pointer 477
Member Access by Pointer 478
14.8 Telling Functions about Structures 478
Using Structure Members 479
Using the Structure Address 480
Passing a Structure as an Argument 481
More on the New, Improved Structure Status 482
Structures or Pointers to Strucures? 485
Functions Using a nArray of Strucures 486
14.9 Saving Structure Contens in a File 488
Program Points 491
14.10 Structures- What's Next? 492
14.11 unions- A Quick Look 492
14.12 typedef- A Quick Look 494
14.13 Functions and Pointers 498
14.14 Summary 500
Review Questions 501
Programming Exercises 503
15 Bit Fiddling
Contents 507
Objectives 507
15.1 Binary Number, Bits and Bytes 508
Binary Integers 508
Signed Integers 509
Binary Floating Pointer 510
15.2 Other Bases 510
Octal 511
Hexadecimal 511
15.3 C's Bitwise Operators 512
Bitwise Logical Operators 512
Usage: Masks 514
Usage: Turning Bits On 514
Usage: Turning BIts Off 515
Usage: Toggling BIts 516
Usage: Checking the Value of a Bit 516
Bitwise Shift Operators 516
Programming Example 518
Another Example 519
15.4 Bit Fields 521
Bit Field Example 522
15.5 Summary 525
Review Questions 526
Programming Exercises 528
16 The C Preprocessor and the C Libray
Contents 529
Objectives 529
16.1 Manifest Constants: #define 530
Tokens 533
Redefining Constants 534
16.2 Using Arguments with #define 535
16.3 Macro or Function? 538
16.4 File Inclusion: #include 539
Header Files: An Example 540
Header File Uses 541
16.5 Other Directives 542
The #undef Directive 542
Conditional Compilation 543
The #error and #pragma Directives 546
16.6 Enumberated Types 546
enum Constants 547
Default Values 547
Assigned Values 547
Usage 548
16.7 The C library 548
Gaining Access to the C Library 548
Using the library Descriptions 549
16.8 The Math Library 550
16.9 The General Utilites Library 553
The qsort() Function 553
Memory Allocation : malloc() and calloc() 556
16.10 Linked Lists 560
The fill_list() Function 563
16.11 Other Directions 564
16.12 Summary 564
Review Questions 565
Programming Exercises 566
Appendices
A Additional Reading 569
B C Operators 571
C Basic Types and Storage Classes 579
D Expressions, Statments, and Program Flow 583
E ASCII Table 591
F Standard I/O Functions (ANSI C) 595
Answers to Odd numberred Review Questions 599
Index 617
