USING C IN SOFTWARE DESIGN TABLE OF CONTENTS Preface Part I CHAPTER 0 SOFTWARE ENGINEERING PRINCIPLES 1 CHAPTER 1 ELEMENTARY PROGRAMMING IN C 3 1.1 History of the C Programming Language 3 1.2 What Is C? 4 1.3 Structure of a Single Unit C Program 5 1.4 Elementary Data Types in C 9 1.5 Output with printf and putchar 12 1.6 Input with scanf and getchar 18 1.7 Constants in C Programs 24 1.8 Documentation and Commenting of C Programs 25 Summary of Chapter 1 26 Exercises 27 CHAPTER 2 CONTROL OF C PROGRAMS 31 2.1 Iteration in C - The for-loop 31 2.2 Iteration in C - The while-loop 35 2.3 Iteration in C - The do-while-loop 39 2.4 Reading an Input Stream with a while-loop 40 2.5 Branching in C - The if and if-else Statements 44 2.6 Branching in C - The switch Statement 50 2.7 The Comma Operator 55 2.8 Processing of an Input stream - An Example 56 Summary of Chapter 2 58 Exercises 59 CHAPTER 3 ARITHMETIC AND OTHER OPERATIONS IN C 63 3.1 Integer Arithmetic 63 3.2 Floating Point and Double-Precision Arithmetic 69 3.3 Precedence of Operations 74 3.4 Reading from Files (Optional) 78 3.5 A Design Project 79 Summary of Chapter 3 80 Exercises 81 CHAPTER 4 FUNCTIONS IN C - ELEMENTARY PROGRAM STRUCTURE 89 4.1 Functions 89 4.2 Passing of Parameters 95 4.3 Storage Classes - Automatic, Static, Extern, Register, and Void 100 4.4 Scope Rules for Functions in a Single Source File 103 4.5 The Type of a Function - Default Types and External Declarations 106 4.6 Type Checking by the C Compiler and lint 111 4.7 The C Preprocessor 113 4.8 Recursion 116 4.9 Library Functions 121 4.10 Software Engineering Project - Requirements 125 4.11 Software Engineering Project - the Next Prototype 128 Summary of Chapter 4 140 Exercises 141 CHAPTER 5 ARRAYS 147 5.1 One-dimensional Arrays of Fixed Size 147 5.2 One-dimensional Arrays of Variable Size 160 5.3 Character Strings 165 5.4 Printf Revisited 168 5.5 Interfacing with the Command Line - Parameters to main() 171 5.6 Two-dimensional Arrays in C 174 5.7 Reading from Files 179 5.8 Recursion Removal (Optional) 181 5.9 Software Engineering Project - Changed Requirements 184 5.10 Software Engineering Project - The Next Prototype 186 Summary of Chapter 5 199 Exercises 200 CHAPTER 6 SUMMARY OF PART I 207 6.1 A Case Study 207 6.2 What You Should Be Able to Do 208 6.3 What You Will Learn in Part II 209 Exercises 210 Part II CHAPTER 7 ADVANCED PROGRAM STRUCTURE 211 7.1 Separate Compilation 213 7.2 The make Utility 217 7.3 The Use of make and Projects in Turbo C 220 7.4 Scope Rules for Programs in Several Source Files 220 7.5 Advanced Documentation and Commenting of C Programs 225 7.6 Libraries 227 7.7 Software Engineering Project - Changed Requirements 229 7.8 Software Engineering Project - The Next Prototype 230 Summary of Chapter 7 232 Exercises 232 CHAPTER 8 POINTERS 235 8.1 Definition of a Pointer 235 8.2 Pointers and Arrays 244 8.3 Pointer Arithmetic 249 8.4 Storage Access - a Case History 256 8.5 lint Revisited 259 8.6 Character Strings Revisited - Pointers and Termination Bytes 260 8.7 Pointers to Functions 262 8.8 Passing Parameters by Reference 272 8.9 Functions with a Variable Number of Arguments 274 8.10 Software Engineering Project - Changed Requirements 277 8.11 Software Engineering Project - The Next Prototype 283 Summary of Chapter 8 285 Exercises 286 CHAPTER 9 STRUCTURED DATA TYPES 297 9.1 Structs 297 9.2 Some Data Structures in C - Lists and Trees 307 9.3 Additional Data Structures in C - Queues 319 9.4 User-defined Data Types and typedef 324 9.5 Unions 334 9.6 Advanced Bit Operations - Fields 343 9.7 Software Engineering Project - Changed Requirements 345 9.8 Software Engineering Project - The Next Prototype 345 Summary of Chapter 9 346 Exercises 348 CHAPTER 10 ADVANCED INPUT AND OUTPUT 353 10.1 File Input and Output in C 353 10.2 General I/O Functions 364 10.3 File Input and Output in C - UNIX Operating System Version 370 10.4 Software Engineering Project - Changed Requirements 377 10.5 Software Engineering Project - The Next Prototype 377 Summary of Chapter 10 379 Exercises 380 CHAPTER 11 BIT OPERATIONS 383 11.1 Why Bit Operations Are Sometimes Necessary 384 11.2 Elementary Bit Operations 389 11.3 Software Engineering Project - Changed Requirements 397 11.4 Software Engineering Project - The Next Prototype 398 Summary of Chapter 11 399 Exercises 399 CHAPTER 12 TOWARDS C++ 403 12.1 C and C++ Solutions to a Simple Problem 403 12.2 Discussion 412 Summary of Chapter 12 413 Exercises 413 APPENDIX 1 RESERVED WORDS IN C 415 APPENDIX 2 THE C STANDARD LIBRARY AND OTHER LIBARRIES 416 APPENDIX 3 SYNTAX SUMMARY 427 APPENDIX 4 A TYPICAL ctype.h FILE 433 APPENDIX 5 PRECEDENCE OF OPERATIONS 434 APPENDIX 6 DIFFERENCES BETWEEN ANSI STANDARD C AND KERNIGHAN & RITCHIE C 436 APPENDIX 7 LIST OF TRADEMARKS 440 REFERENCES 441 INDEX 442