Tài liệu Practical C Programming Third Edition pdf

456 3K 7
Tài liệu Practical C Programming Third Edition pdf

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

Practical C Programming Practical C Programming Third Edition Steve Oualline Beijing • Cambridge • Farnham • Kưln • Sebastopol • Tokyo Practical C Programming, Third Edition by Steve Oualline Copyright © 1997, 1993, 1991 O’Reilly Media, Inc All rights reserved Printed in the United States of America Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472 Editor, First and Second Editions: Tim O’Reilly Editor, Third Edition: Andy Oram Production Editor: Nicole Gipson Arigo Printing History: July 1991: First Edition August 1992: Minor corrections January 1993: Second Edition Bugs fixed; programs all now conform to ANSI C June 1993: Minor corrections August 1997: Third Edition Nutshell Handbook, the Nutshell Handbook logo, and the O’Reilly logo are registered trademarks and The Java Series is a trademark of O’Reilly Media, Inc Practical C Programming, Third Edition, the image of a cow, and related trade dress are trademarks of O’Reilly Media, Inc Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks Where those designations appear in this book, and O’Reilly Media, Inc was aware of a trademark claim, the designations have been printed in caps or initial caps While every precaution has been taken in the preparation of this book, the publisher assumes no responsibility for errors or omissions, or for damages resulting from the use of the information contained herein ISBN: 978-1-565-92306-5 [LSI] [2011-02-02] Table of Contents Preface xv How This Book is Organized xvi Chapter by Chapter xvi Notes on the Third Edition .xix Font Conventions xix Obtaining Source Code xx Comments and Questions .xxii Acknowledgments xxii Acknowledgments to the Third Edition .xxiii I Basics 1 What Is C? How Programming Works Brief History of C .6 How C Works .7 How to Learn C Basics of Program Writing .11 Programs from Conception to Execution .11 Creating a Real Program 12 Creating a Program Using a Command-Line Compiler 13 Creating a Program Using an Integrated Development Environment 16 Getting Help on UNIX .33 v vi Table of Contents Getting Help in an Integrated Development Environment 34 IDE Cookbooks 34 Programming Exercises 37 Style 38 Common Coding Practices 42 Coding Religion 45 Indentation and Code Format 45 Clarity 46 Simplicity 47 Summary 48 Basic Declarations and Expressions .49 Elements of a Program 49 Basic Program Structure 50 Simple Expressions 51 Variables and Storage 52 Variable Declarations .53 Integers .54 Assignment Statements 54 printf Function 56 Floating Point 57 Floating Point Versus Integer Divide 58 Characters 60 Answers 61 Programming Exercises 62 Arrays, Qualifiers, and Reading Numbers 63 Arrays 63 Strings .64 Reading Strings 67 Multidimensional Arrays 70 Reading Numbers .71 Initializing Variables 73 Types of Integers .75 Types of Floats 77 Constant Declarations 77 Table of Contents vii Hexadecimal and Octal Constants 78 Operators for Performing Shortcuts 78 Side Effects .79 ++x or x++ 80 More Side-Effect Problems 81 Answers 82 Programming Exercises 83 Decision and Control Statements 84 if Statement .84 else Statement 85 How Not to Use strcmp 86 Looping Statements 87 while Statement 87 break Statement 89 continue Statement 90 Assignment Anywhere Side Effect 91 Answer 92 Programming Exercises 93 Programming Process 95 Setting Up 97 Specification .98 Code Design .98 Prototype 99 Makefile 101 Testing 104 Debugging 104 Maintenance 107 Revisions 107 Electronic Archaeology 107 Marking Up the Program 108 Using the Debugger 108 Text Editor as a Browser 108 Add Comments 109 Programming Exercises 111 viii Table of Contents II Simple Programming 113 More Control Statements 115 for Statement 115 switch Statement 118 switch, break, and continue 123 Answers 124 Programming Exercises 125 Variable Scope and Functions 127 Scope and Class 127 Functions 130 Functions with No Parameters 134 Structured Programming 135 Recursion 136 Answers 138 Programming Exercises 138 10 C Preprocessor 140 #define Statement 140 Conditional Compilation 146 include Files 148 Parameterized Macros 150 Advanced Features 152 Summary 152 Answers 152 Programming Exercises 154 11 Bit Operations 156 Bit Operators 158 The and Operator (&) 158 Bitwise or (|) 160 The Bitwise Exclusive or (^) 161 The Ones Complement Operator (Not) (~) 161 The Left- and Right-Shift Operators () 162 Setting, Clearing, and Testing Bits 163 Bitmapped Graphics 166 416 Glossary Segmentation violation An error caused by a program trying to access memory outside its address space Caused by dereferencing a bad pointer Set a bit The operation of setting a specified bit to one This operation is not a defined operation in C Shift The operation of moving the bits in a bit field either left or right short An arithmetic data type that is the same size, or smaller, than an integer Side effect An operation performed in addition to the main operation of a statement such as incrementing a variable in an assignment statement: result = begin++end; Significand The most significant digits of a floating-point number without regard to placement of the radix point Significant digits A digit that must be kept to preserve a given accuracy Single quote (') ASCII character 39 Used in C to delimit a single character sizeof Operator that returns the size, in bytes, of a data type of variable Source code Symbolic coding in its original form before being translated by a computer Source file A file containing source code Specification A document that describes what the program does sprintf Similar to fprintf except that it uses a string output sscanf A library input routine Stack An area of memory used to hold a list of data and instructions on a temporary basis Glossary 417 Stack variable See Temporary variable Stack overflow An error caused by a program using too much temporary space (stack space) for its variables Caused by a big program or by infinite recursion static A storage class attribute Inside a set of curly braces, it indicates a permanent variable Outside a set of curly braces, it indicates a file-local variable stderr Predefined standard error file stdin Predefined input source stdio.h The C standard I/O package stdout Predefined standard output Storage class An attribute of a variable definition that controls how the variable will be stored in memory String A sequence or array of characters struct A C keyword that identifies a structure data type Structure A hierarchical set of names that refers to an aggregate of data items that may have different attributes Style sheet A document that describes the style of programming used by a particular company or institution Sunview A graphics and windowing system available on SUN workstations switch A multiway branch that transfers control to one of several case statements based on the value of an index expression Syntax Rules that govern the construction of statements 418 Glossary Syntax error An error in the proper construction of a C expression Temporary variable A variable whose storage is allocated from the stack It is initialized each time the block in which it is defined is entered It exists only during the execution of that block Test a bit The operation of determining if a particular bit is set This operation is not defined in C Test plan A specification of the tests that a program must undergo Text editor Software used to create or alter text files Translation Creation of a new program in an alternate language logically equivalent to an existing program in a source language Tree A hierarchical data structure Truncation An operation on a real number whereby any fractional part is discarded Turbo C++ A version of the C++ language for personal computers developed by Borland Typecast See Cast typedef A operator used to create new types from existing types typing statement A statement that establishes the characteristics of a variable Unbuffered I/O Each read or write results in a system call union A data type that allows different data names and data types to be assigned to the same storage location UNIX A popular multiuser operating system first developed by Ken Thompson and Dennis Ritchie of the Bell Telephone Laboratories Glossary 419 unsigned A qualifier for specifying int and char variables that not contain negative numbers Upgrading Modification of a program to provide improved performance or new features value A quantity assigned to a constant Variable A name that refers to a value The data represented by the variable name can, at different times during the execution of a program, assume different values Variable name The symbolic name given to a section of memory used to store a variable Version A term used to identify a particular edition of software A customary practice is to include a version number Whole numbers indicate major rewrites Fractions indicate minor rewrites or corrections of problems void A data type in C When used as a parameter in a function call, it indicates that there is no return value void * indicates that a generic pointer value is returned volatile A C keyword that indicates that the value of a variable or constant can be changed at any time This attribute is used for memory mapped I/O, shared memory applications, and other advanced programming while An iterative statement that repeats a statement as long as a given condition is true Windows Also knows as MS-Windows An operating system developed for personal computers by Microsoft Corporation Also a new operating system with a similar user interface and API such as Windows NT and Windows 95 X Window System A graphics and windowing system available from the X Consortium that is currently running on many computing systems Zero-based counting A system of counting by which the first object is given the count zero rather than one Index Symbols and Numbers & (address of operator), 185 & (and operator), 158, 185 & vs &&, 159 * operator (dereference), 185 != operator (not equal), 85 ^ (exclusive or), 158, 161 , operator (comma), 85, 346 {} (curly braces), 85 " (double quote), 60 operator (decrement), 78 = versus ==, 10, 91 == operator (equal), 85, 105, 382 operator (greater than), 85 -> operator (structure pointer), 287 >= operator (greater than or equal to), 85 >> (right shift), 158, 162 ++ operator (increment), 78 += operator (increase), 79 ’ (single quotes), 60 ~ (complement operator), 158, 161 | (or operator), 158, 160 character, 64 A abstract class, 356 accuracy, floating point, 269, 270 addition operator (+), 51 addition, floating point, 266 address of operator (&), 185 alignment restrictions, 339 ambiguous code, 86 and operator (&), 158 and portability, 338 argc, 201 argv, 201 array declarations, arrays, 63, 181 dimension of, 63 elements of, 63 index, 64 infinite, 310, 313, 316 initializing, 73 multi-dimensional, 74 and pointers, 189, 191 of structures, 181 ASCII characters, 60 files, 215–216 assembly language, assignment statements, 8, 382 author, 40 auto, 130 automatic parameter changes, 194 automatic variables, 130 B binary files, 215–216, 338 I/O, 218 mode for fopen (b), 216 trees, 292 421 422 bit fields, 179, 181 bit operations, 156 bit operators, 158 bitmapped graphics, 166, 167 bits, 54, 156, 163–164 bitwise and (&), 158 bitwise complement (~), 158, 161 bitwise exclusive or (^), 158, 161 bitwise left shift (), 158, 162 bitwise shift left (

Ngày đăng: 14/02/2014, 20:20

Từ khóa liên quan

Mục lục

  • Table of Contents

  • Preface

    • How This Book is Organized

    • Chapter by Chapter

    • Notes on the Third Edition

    • Font Conventions

    • Obtaining Source Code

      • FTP

      • FTPMAIL

      • Comments and Questions

      • Acknowledgments

      • Acknowledgments to the Third Edition

      • I

      • What Is C?

        • How Programming Works

        • Brief History of C

        • How C Works

        • How to Learn C

        • Basics of Program Writing

          • Programs from Conception to Execution

            • Wrappers

            • Creating a Real Program

            • Creating a Program Using a Command- Line Compiler

              • Step 1. Create a Place for Your Program

              • Step 2. Create the Program

              • Step 3. Run the Compiler

                • UNIX cc compiler (generic UNIX)

Tài liệu cùng người dùng

Tài liệu liên quan