Practical C Programming. Steve Oualline

Similar documents
Practical C++ Programming

C Programming. Course Outline. C Programming. Code: MBD101. Duration: 10 Hours. Prerequisites:

C Programming for Electronic Engineers


The Waite Group's. New. Primer Plus. Second Edition. Mitchell Waite and Stephen Prata SAMS

Preface... (vii) CHAPTER 1 INTRODUCTION TO COMPUTERS

Rule 1-3: Use white space to break a function into paragraphs. Rule 1-5: Avoid very long statements. Use multiple shorter statements instead.

C Programming SYLLABUS COVERAGE SYLLABUS IN DETAILS

P.G.TRB - COMPUTER SCIENCE. c) data processing language d) none of the above

DETAILED SYLLABUS INTRODUCTION TO C LANGUAGE

CS201 - Introduction to Programming Glossary By

Short Notes of CS201

Writing an ANSI C Program Getting Ready to Program A First Program Variables, Expressions, and Assignments Initialization The Use of #define and

C-LANGUAGE CURRICULAM

Contents. Preface. Introduction. Introduction to C Programming

CS 326 Operating Systems C Programming. Greg Benson Department of Computer Science University of San Francisco

A Fast Review of C Essentials Part I

Contents. Figures. Tables. Examples. Foreword. Preface. 1 Basics of Java Programming 1. xix. xxi. xxiii. xxvii. xxix

CHAPTER 1 Introduction to Computers and Programming CHAPTER 2 Introduction to C++ ( Hexadecimal 0xF4 and Octal literals 031) cout Object

Welcome to Teach Yourself Acknowledgments Fundamental C++ Programming p. 2 An Introduction to C++ p. 4 A Brief History of C++ p.

SOME ASSEMBLY REQUIRED

INTRODUCTION 1 AND REVIEW

Fundamental Data Types. CSE 130: Introduction to Programming in C Stony Brook University

CERTIFICATE IN WEB PROGRAMMING

Writing Program in C Expressions and Control Structures (Selection Statements and Loops)

BLM2031 Structured Programming. Zeyneb KURT

Mastering BorlandC++ 4.5

Part I Part 1 Expressions

CSCI 171 Chapter Outlines

Introduction to Programming Using Java (98-388)

Lecture 03 Bits, Bytes and Data Types

CS Programming In C


C for Electronic Engineering

Software Development & Education Center C Programming

>B<82. 2Soft ware. C Language manual. Copyright COSMIC Software 1999, 2001 All rights reserved.

IECD Institute for Entrepreneurship and Career Development Bharathidasan University, Tiruchirappalli 23.

C OVERVIEW BASIC C PROGRAM STRUCTURE. C Overview. Basic C Program Structure

CMPE-013/L. Introduction to C Programming

I BCA[ ] SEMESTER I CORE: C PROGRAMMING - 106A Multiple Choice Questions.

C OVERVIEW. C Overview. Goals speed portability allow access to features of the architecture speed

Variables Data types Variable I/O. C introduction. Variables. Variables 1 / 14

Programming Fundamentals (CS 302 ) Dr. Ihsan Ullah. Lecturer Department of Computer Science & IT University of Balochistan

C Programming Language (Chapter 2 of K&R) Variables and Constants

Model Viva Questions for Programming in C lab

KLiC C Programming. (KLiC Certificate in C Programming)

5.Coding for 64-Bit Programs

EL6483: Brief Overview of C Programming Language

CS201- Introduction to Programming Latest Solved Mcqs from Midterm Papers May 07,2011. MIDTERM EXAMINATION Spring 2010

VALLIAMMAI ENGINEERING COLLEGE SRM NAGAR, KATTANGULATHUR

CS113: Lecture 3. Topics: Variables. Data types. Arithmetic and Bitwise Operators. Order of Evaluation

Introduction to C Language

Work relative to other classes

APPENDIX A : Example Standard <--Prev page Next page -->

Class 9 Saturday, Feb 14

OBJECTIVE QUESTIONS: Choose the correct alternative:

M4.1-R3: PROGRAMMING AND PROBLEM SOLVING THROUGH C LANGUAGE

Topic 6: A Quick Intro To C. Reading. "goto Considered Harmful" History

Lecture 02 C FUNDAMENTALS

AIR FORCE SCHOOL,BAMRAULI COMPUTER SCIENCE (083) CLASS XI Split up Syllabus (Session ) Contents

Appendix G C/C++ Notes. C/C++ Coding Style Guidelines Ray Mitchell 475

Fundamentals of Programming

B.V. Patel Institute of Business Management, Computer & Information Technology, Uka Tarsadia University

CS201 Latest Solved MCQs

Absolute C++ Walter Savitch

Chapter1 Overview of computers

Java Fundamentals p. 1 The Origins of Java p. 2 How Java Relates to C and C++ p. 3 How Java Relates to C# p. 4 Java's Contribution to the Internet p.

Features of C. Portable Procedural / Modular Structured Language Statically typed Middle level language

C++ Style Guide. 1.0 General. 2.0 Visual Layout. 3.0 Indentation and Whitespace

Computers Programming Course 5. Iulian Năstac

Tokens, Expressions and Control Structures

CODE TIME TECHNOLOGIES. Abassi RTOS MISRA-C:2004. Compliance Report

Programming Language Basics

Language Translation. Compilation vs. interpretation. Compilation diagram. Step 1: compile. Step 2: run. compiler. Compiled program. program.

1 Chapter Plan...1 Exercise - Simple Program...2

Course Title: C Programming Full Marks: Course no: CSC110 Pass Marks: Nature of course: Theory + Lab Credit hours: 3

A flow chart is a graphical or symbolic representation of a process.

Borland 105, 278, 361, 1135 Bounded array Branch instruction 7 break statement 170 BTree 873 Building a project 117 Built in data types 126

CSE 374 Programming Concepts & Tools. Brandon Myers Winter 2015 C: Linked list, casts, the rest of the preprocessor (Thanks to Hal Perkins)

Review of the C Programming Language for Principles of Operating Systems

M1-R4: Programing and Problem Solving using C (JAN 2019)

L2 - C language for Embedded MCUs

Advanced C Programming Topics

Contents. 1 Introduction to Computers, the Internet and the World Wide Web 1. 2 Introduction to C Programming 26

Language Reference Manual simplicity

BİL200 TUTORIAL-EXERCISES Objective:

CONTENTS. PART 1 Structured Programming 1. 1 Getting started 3. 2 Basic programming elements 17

Modesto Junior College Course Outline of Record CMPSC 241

Lecture 2: C Programming Basic

Split up Syllabus (Session )

M1-R4: Programing and Problem Solving using C (JULY 2018)

Fundamental of Programming (C)

Overview of C. Basic Data Types Constants Variables Identifiers Keywords Basic I/O

C - Basics, Bitwise Operator. Zhaoguo Wang

The C Programming Language Guide for the Robot Course work Module

Presented By : Gaurav Juneja

CNG 140 C Programming. Syllabus. Course Info Fall Semester. Catalog Description

Quiz Start Time: 09:34 PM Time Left 82 sec(s)

Computer Organization & Systems Exam I Example Questions

BIL 104E Introduction to Scientific and Engineering Computing. Lecture 4

Transcription:

Practical C Programming Steve Oualline

Preface Scope of This Handbook Conventions Used in This Handbook Acknowledgments xviii xix xx i xxii Chapter 1 The Basics of Program Writing 1 Text Editor 2 Compiler 3 The Library 3 The Linker 3 make Utility 5 Debugger 5 Wrappers and Integrated Development Environments 5 A Simple Example 6 Getting Help 7 Chapter 2 Style 9 Common Coding Practices 14 Coding Religion 16 Indentation and Code Format 16 Clarity 17 Simplicity 1 8 Summary J *f

Chapter 3 Basic Declarations and Expressions + 20 Elements of a Program :. 20 Basic Program Structure : 21 Simple Expressions :::...+ :.. :N : 2 3 BELVii-Nt k än torage ::; ~,...K 24 Variable Declarations 2 5 Integers r... 2 6 Assignment' Statements 2 6 printf Function.... 2 8 Floating Point x, 29 Floating Point Versus Integer Divide 30 haracters r 3 2 Answers 3 3 Programming Exercises 34 Chapter 4 Arrays, Qualifiers, and Reading Numbers 3 5 Arrays 35 Strings 37 r ''Reading Strings 40 Multiple Dimensional Arrays 43 Reading Numbers 44 Initializing Variables 46 Types of Integers 4 8 Types of Floats 4 9 Hexadecimal and Octal Constants 5 0 Operators for Performing Shortcuts 5 1 Side Effects 52 Answers 55 Programming Exercises... 56 Chapter 5 Decision and Control Statements 5 7 if Statement 5 8._l e_statement 59 How. of to Use strcm p i pin tatements 60.

while Statement 6 1 break Statement 63 continue Statement 65 The Assignment Anywhere Side Effect 66 Answers 67 Programming Problems 6 7 Chapter 6 The Programming Process 69 Setting Up 7 1 The Specification 72 Code Design 74 The Prototype 74 The Makefile 76 Testing ~ 77 Debugging 7 8 Maintenance 8 0 Revisions 8 1 Electronic Archaeology 8 1 Marking Up the Program 82 Using the Debugger 82 _ Text Editor as a Browser 82 Add Comments 8 3 Programming Exercises 86 Chapter 7 More Control Statements 87 for Statement 8 7 switch Statement 9 1 switch, break, and continue 96 Answers 9 8 Programming Exercises x.98 7. r'

Chapter 8 Variable Scope and Functions 1 '100 Scope and Class 100 Functions 10 4 Older-style K&R Function Declarations 10 8 Functions With No Parameters 108 Structured Programming 110 Recursion 11 2 Answers 11 3 Programming Exercises 114 Chapter 9 The C Preprocessor 11 5 #define Statement 11 6 Conditional Compilation 12 1 Include Files 12 3 Parameterized Macros 125 Advanced Features 126 Summary 12 7 Answers 12 7 Programming Exercises 13 0 Chapter 10 Bit Operations 13 1 Bit Operators 132 The and Operator 13 3 Bitwise or 135 The Bitwise Exclusive or 135 The Ones Complement Operator (not) 136 The Left and Right Shift Operators 136 Setting, Clearing, and Testing Bits 13 7 Bitmapped Graphics 14 0 Answers 144 Programming Exercises 144

Chapter 11 Advanced Types 146 Structures 146 Unions 149 typedef 15 1 enum Type 152 Bit Fields or Packed Structures 15 3 Arrays of Structures 15 5 Summary 15 6 Programming Exercises 15 6 Chapter 12 Simple Pointers 15 8 Pointers and Arrays 16 7 Splitting 17 1 Pointers and Structures 174 Command-line Arguments 17 5 Answers 180 Programming Problems 18 1 Chapter 13 File Input/Output 182 Conversion Routines 185 Binary and ASCII Files 18 8 The End-of-line Puzzle 18 9 Binary I/O 19 1 Buffering Problems 192 Unbuffered I/O 192 Designing File Formats 197 Answers 19 9 Programming Problems 200

Chapter 14 Debugging and Optimization 20 1 Debugging 20 1 Divide and Conquer 210 Debug Only Code 210 Debug Command-line Switch 210 Going Through the Output 212 Interactive Debuggers 212 Debugging a Binary Search 216 Runtime Errors 226 The Confessional Method of Debugging 22 8 Optimization 229 The Power of Powers of 2 23 1 How to Optimize 234 Case Study : Macros Versus Functions 236 Case Study : Optimizing a Color Rendering Algorithm 236 Answers 23 7 Programming Problems 237 Chapter 15 Floating Point 23 8 Floating-point Format 239 Floating Addition/Subtraction 240 Multiplication 24 1 Division 24 1 Overflow and Underflow 24 2 Roundoff Error 24 2 Accuracy 24 3 Minimizing Roundoff Error 244 Accuracy 244 Precision and Speed 246 Power Series 24 7 Programming Problems 249

Chapter 16 Advanced Pointers 250 Pointers and Structures : 25 1 free Function 25 4 Linked List 25 5 Structure Pointer Operator 259 Ordered Linked Lists 259 Double-linked List 262 Trees 267 Printing a Tree 270 The Rest of the Program 27 1 Data Structures for a Chess Program 275 Answers 277 Programming Problems 279 Chapter 17 Modular Programming 280 Modules 280 Public and Private 28 1 The extern Modifier 28 1 Headers 284 The Body of the Module 286 A Program to Use Infinite Arrays 286 The Makefile for Multiple Files 289 Using the Infinite Array 293 Dividing a Task Up into Modules 298 Module Division Example : Text Editor 299 Compiler 30 1 Spreadsheet 303 Module Design Guidelines 305 Programming Problems 305 Chapter 18 Portability Problems 306 Modularity - 11II-.............................................................................................. 3 0 Word Size r..e_'f30 7 Byte Order Problem 30 8 Alignment Problem 309

NULL Pointer Problem 310 Filename Problems 31 1 File Types r 312 Summary 31 2 Answers 31 2 Chapter 19 C's Dustier Comers 314 do/while 31 4 goto 31 5 The?: Construct 316 The, Operator 316 Answers 31 7 Chapter 20 Putting It All Together 318 Assignment 31 8 Specification 31 9 Code Design 32 1 Main Module 32 1 Macro Module 32 2 Font Module 322 Symbol Table Module 322 Coding 323 Functional Description 323 tlint.c 324 macros.c 324 font.c 325 symbol.c 325 Testing 32 6 Revisions 32 7 Program Files 32 7 The gen.h File 32 7 The font.h File 32 8 The macro.h File 32 8 The tlint.c File 329 The macros.c File.............................. 33 1 The fonts.c File 33 9 The symbol.c File 340

UNIX Makefile : 34 2 Turbo C Makefile 342 The standard.mac File 34 3 The standard.fonts File 34 5 Test Script 34 5 The troff.test File 346 The Bad.mac File 347 The Two.font File 347 Programming Problems 347 Chapter 21 Programming Adages { r.... R 348 General....,- 348 Design 349 Declarations 349 switch Statement 350 Preprocessor 350 Style 35 1 Compiling 35 1 Final Note 35 1 Answers Appendix A ASCII Chart 353 Appendix B Numeric Limits 35 6 Ranges 35 6 Appendix C Operator Precedence Rules 35 8 ANSI Standard Rules 358 Practical Subset,.ti 359

_Appendix D Program to Compute sine Using a Power Series 360 Makefile. ::::;.:.a.::.:..::.:..:. :...::....~...:.. b : 36 1 The sine.c Program 36 1 Appendix E Automatic Type Conversion Used When Passing Parameters... 36 5 Glossary 366 Index 388