Free Shipping on orders over $25

Book Details

  • Paperback
  • Bookstore's Wholesale Price: $107
  • March 2008
  • ISBN: 978-0-393-97950-3
  • 7.5 × 9.3 in / 832 pages
  • Territory Rights: Worldwide

More Textbooks

  1. Computer Science

C Programming

A Modern Approach

Second Edition

Paperback

See all options and formats starting at
$133.75

K. N. King (Author, Georgia State University)

 

The first edition of C Programming: A Modern Approach was popular with students and faculty alike because of its clarity and comprehensiveness as well as its trademark Q&A sections.

Professor King's spiral approach made it accessible to a broad range of readers, from beginners to more advanced students. With adoptions at over 225 colleges, the first edition was one of the leading C textbooks of the last ten years. The second edition maintains all the book's popular features and brings it up to date with coverage of the C99 standard. The new edition also adds a significant number of exercises and longer programming projects, and includes extensive revisions and updates.

More...

    Preface

    1 INTRODUCING C

    1. 1.1 History of C
      1. Origins
      2. Standardization
      3. C-Based Languages
    2. 1.2 Strengths and Weaknesses of C
      1. Strengths
      2. Weaknesses
      3. Effective Use of C

    2 C FUNDAMENTALS

    1. 2.1 Writing a Simple Program
      1. Program: Printing a Pun
      2. Compiling and Linking
      3. Integrated Development Environments
    2. 2.2 The General Form of a Simple Program
      1. Directives
      2. Functions
      3. Statements
      4. Printing Strings
    3. 2.3 Comments
    4. 2.4 Variables and Assignment
      1. Types
      2. Declarations
      3. Assignment
      4. Printing the Value of a Variable
      5. Program: Computing the Dimensional Weight of a Box
      6. Initialization
      7. Printing Expressions
    5. 2.5 Reading Input
      1. Program: Computing the Dimensional Weight of a Box (Revisited)
    6. 2.6 Defining Names for Constants
      1. Program: Converting from Fahrenheit to Celsius
    7. 2.7 Identifiers
      1. Keywords
    8. 2.8 Layout of a C Program

    3 FORMATTED INPUT/OUTPUT

    1. 3.1 The printf Function
      1. Conversion Specifications
      2. Program: Using printf to Format Numbers
      3. Escape Sequences
    2. 3.2 The scanf Function
      1. How scanf Works
      2. Ordinary Characters in Format Strings
      3. Confusing printf with scanf
      4. Program: Adding Fractions

    4 EXPRESSIONS

    1. 4.1 Arithmetic Operators
      1. Operator Precedence and Associativity
      2. Program: Computing a UPC Check Digit
    2. 4.2 Assignment Operators
      1. Simple Assignment
      2. Lvalues
      3. Compound Assignment
    3. 4.3 Increment and Decrement Operators
    4. 4.4 Expression Evaluation
      1. Order of Subexpression Evaluation
    5. 4.5 Expression Statements

    5 SELECTION STATEMENTS

    1. 5.1 Logical Expressions
      1. Relational Operators
      2. Equality Operators
      3. Logical Operators
    2. 5.2 The if Statement
      1. Compound Statements
      2. The else Clause
      3. Cascaded if Statements
      4. Program: Calculating a Broker’s Commission
      5. The “Dangling else” Problem
      6. Conditional Expressions
      7. Boolean Values in C89
      8. Boolean Values in C99
    3. 5.3 The switch Statement
      1. The Role of the break Statement
      2. Program: Printing a Date in Legal Form

    6 LOOPS

    1. 6.1 The while Statement
      1. Infinite Loops
      2. Program: Printing a Table of Squares
      3. Program: Summing a Series of Numbers
    2. 6.2 The do Statement
      1. Program: Calculating the Number of Digits in an Integer
    3. 6.3 The for Statement
      1. for Statement Idioms
      2. Omitting Expressions in a for Statement
      3. for Statements in C99
      4. The Comma Operator
      5. Program: Printing a Table of Squares (Revisited)
    4. 6.4 Exiting from a Loop
      1. The break Statement
      2. The continue Statement
      3. The goto Statement
      4. Program: Balancing a Checkbook
    5. 6.5 The Null Statement

    7 BASIC TYPES

    1. 7.1 Integer Types
      1. Integer Types in C99
      2. Integer Constants
      3. Integer Constants in C99
      4. Integer Overflow
      5. Reading and Writing Integers
      6. Program: Summing a Series of Numbers (Revisited)
    2. 7.2 Floating Types
      1. Floating Constants
      2. Reading and Writing Floating-Point Numbers
    3. 7.3 Character Types
      1. Operations on Characters
      2. Signed and Unsigned Characters
      3. Arithmetic Types
      4. Escape Sequences
      5. Character-Handling Functions
      6. Reading and Writing Characters using scanf and printf
      7. Reading and Writing Characters using getchar and putchar
      8. Program: Determining the Length of a Message
    4. 7.4 Type Conversion
      1. The Usual Arithmetic Conversions
      2. Conversion During Assignment
      3. Implicit Conversions in C99
      4. Casting
    5. 7.5 Type Definitions
      1. Advantages of Type Definitions
      2. Type Definitions and Portability
    6. 7.6 The sizeof Operator

    8 ARRAYS

    1. 8.1 One-Dimensional Arrays
      1. Array Subscripting
      2. Program: Reversing a Series of Numbers
      3. Array Initialization
      4. Designated Initializers
      5. Program: Checking a Number for Repeated Digits
      6. Using the sizeof Operator with Arrays
      7. Program: Computing Interest
    2. 8.2 Multidimensional Arrays
      1. Initializing a Multidimensional Array
      2. Constant Arrays
      3. Program: Dealing a Hand of Cards
    3. 8.3 Variable-Length Arrays (C99)

    9 FUNCTIONS

    1. 9.1 Defining and Calling Functions
      1. Program: Computing Averages
      2. Program: Printing a Countdown
      3. Program: Printing a Pun (Revisited)
      4. Function Definitions
      5. Function Calls
      6. Program: Testing Whether a Number Is Prime
    2. 9.2 Function Declarations
    3. 9.3 Arguments
      1. Argument Conversions
      2. Array Arguments
      3. Variable-Length Array Parameters
      4. Using static in Array Parameter Declarations
      5. Compound Literals
    4. 9.4 The return Statement
    5. 9.5 Program Termination
      1. The exit Function
    6. 9.6 Recursion
      1. The Quicksort Algorithm
      2. Program: Quicksort

    10 PROGRAM ORGANIZATION

    1. 10.1 Local Variables
      1. Static Local Variables
      2. Parameters
    2. 10.2 External Variables
      1. Example: Using External Variables to Implement a Stack
      2. Pros and Cons of External Variables
      3. Program: Guessing a Number
    3. 10.3 Blocks
    4. 10.4 Scope
    5. 10.5 Organizing a C Program
      1. Program: Classifying a Poker Hand

    11 POINTERS

    1. 11.1 Pointer Variables
      1. Declaring Pointer Variables
    2. 11.2 The Address and Indirection Operators
      1. The Address Operator
      2. The Indirection Operator
    3. 11.3 Pointer Assignment
    4. 11.4 Pointers as Arguments
      1. Program: Finding the Largest and Smallest Elements in an Array
      2. Using const to Protect Arguments
    5. 11.5 Pointers as Return Values

    12 POINTERS AND ARRAYS

    1. 12.1 Pointer Arithmetic
      1. Adding an Integer to a Pointer
      2. Subtracting an Integer from a Pointer
      3. Subtracting One Pointer from Another
      4. Comparing Pointers
      5. Pointers to Compound Literals
    2. 12.2 Using Pointers for Array Processing
      1. Combining the * and ++ Operators
    3. 12.3 Using an Array Name as a Pointer
      1. Program: Reversing a Series of Numbers (Revisited)
      2. Array Arguments (Revisited)
      3. Using a Pointer as an Array Name
    4. 12.4 Pointers and Multidimensional Arrays
      1. Processing the Elements of a Multidimensional Array
      2. Processing the Rows of a Multidimensional Array
      3. Processing the Columns of a Multidimensional Array
      4. Using the Name of a Multidimensional Array as a Pointer
    5. 12.5 Pointers and Variable-Length Arrays (C99)

    13 STRINGS

    1. 13.1 String Literals
      1. Escape Sequences in String Literals
      2. Continuing a String Literal
      3. How String Literals Are Stored
      4. Operations on String Literals
      5. String Literals versus Character Constants
    2. 13.2 String Variables
      1. Initializing a String Variable
      2. Character Arrays versus Character Pointers
    3. 13.3 Reading and Writing Strings
      1. Writing Strings Using printf and puts
      2. Reading Strings Using scanf and gets
      3. Reading Strings Character by Character
    4. 13.4 Accessing the Characters in a String
    5. 13.5 Using the C String Library
      1. The strcpy (String Copy) Function
      2. The strlen (String Length) Function
      3. The strcat (String Concatenation) Function
      4. The strcmp (String Comparison) Function
      5. Program: Printing a One-Month Reminder List
    6. 13.6 String Idioms
      1. Searching for the End of a String
      2. Copying a String
    7. 13.7 Arrays of Strings
      1. Command-Line Arguments
      2. Program: Checking Planet Names

    14 THE PREPROCESSOR

    1. 14.1 How the Preprocessor Works
    2. 14.2 Preprocessing Directives
    3. 14.3 Macro Definitions
      1. Simple Macros
      2. Parameterized Macros
      3. The # Operator
      4. The ## Operator
      5. General Properties of Macros
      6. Parentheses in Macro Definitions
      7. Creating Longer Macros
      8. Predefined Macros
      9. Additional Predefined Macros in C99
      10. Empty Macro Arguments
      11. Macros with a Variable Number of Arguments
      12. The __func__ Identifier
    4. 14.4 Conditional Compilation
      1. The #if and #endif Directives
      2. The defined Operator
      3. The #ifdef and #ifndef Directives
      4. The #elif and #else Directives
      5. Uses of Conditional Compilation
    5. 14.5 Miscellaneous Directives
      1. The #error Directive
      2. The #line Directive
      3. The #pragma Directive
      4. The _Pragma Operator

    15 WRITING LARGE PROGRAMS

    1. 15.1 Source Files
    2. 15.2 Header Files
      1. The #include Directive
      2. Sharing Macro Definitions and Type Definitions
      3. Sharing Function Prototypes
      4. Sharing Variable Declarations
      5. Nested Includes
      6. Protecting Header Files
      7. #error Directives in Header Files
    3. 15.3 Dividing a Program into Files
      1. Program: Text Formatting
    4. 15.4 Building a Multiple-File Program
      1. Makefiles
      2. Errors During Linking
      3. Rebuilding a Program
      4. Defining Macros Outside a Program

    16 STRUCTURES, UNIONS, AND ENUMERATIONS

    1. 16.1 Structure Variables
      1. Declaring Structure Variables
      2. Initializing Structure Variables
      3. Designated Initializers
      4. Operations on Structures
    2. 16.2 Structure Types
      1. Declaring a Structure Tag
      2. Defining a Structure Type
      3. Structures as Arguments and Return Values
      4. Compound Literals
    3. 16.3 Nested Arrays and Structures
      1. Nested Structures
      2. Arrays of Structures
      3. Initializing an Array of Structures
      4. Program: Maintaining a Parts Database
    4. 16.4 Unions
      1. Using Unions to Save Space
      2. Using Unions to Build Mixed Data Structures
      3. Adding a “Tag Field” to a Union
    5. 16.5 Enumerations
      1. Enumeration Tags and Type Names 4
      2. Enumerations as Integers
      3. Using Enumerations to Declare “Tag Fields”

    17 ADVANCED USES OF POINTERS

    1. 17.1 Dynamic Storage Allocation
      1. Memory Allocation Functions
      2. Null Pointers
    2. 17.2 Dynamically Allocated Strings
      1. Using malloc to Allocate Memory for a String
      2. Using Dynamic Storage Allocation in String Functions
      3. Arrays of Dynamically Allocated Strings
      4. Program: Printing a One-Month Reminder List (Revisited)
    3. 17.3 Dynamically Allocated Arrays
      1. Using malloc to Allocate Storage for an Array
      2. The calloc Function
      3. The realloc Function
    4. 17.4 Deallocating Storage
      1. The free Function
      2. The “Dangling Pointer” Problem
    5. 17.5 Linked Lists
      1. Declaring a Node Type
      2. Creating a Node
      3. The -> Operator
      4. Inserting a Node at the Beginning of a Linked List
      5. Searching a Linked List
      6. Deleting a Node from a Linked List
      7. Ordered Lists
      8. Program: Maintaining a Parts Database (Revisited)
    6. 17.6 Pointers to Pointers
    7. 17.7 Pointers to Functions
      1. Function Pointers as Arguments
      2. The qsort Function
      3. Other Uses of Function Pointers
      4. Program: Tabulating the Trigonometric Functions
    8. 17.8 Restricted Pointers (C99)
    9. 17.9 Flexible Array Members (C99)

    18 DECLARATIONS

    1. 18.1 Declaration Syntax
    2. 18.2 Storage Classes
      1. Properties of Variables
      2. The auto Storage Class
      3. The static Storage Class
      4. The extern Storage Class
      5. The register Storage Class
      6. The Storage Class of a Function
      7. Summary
    3. 18.3 Type Qualifiers
    4. 18.4 Declarators
      1. Deciphering Complex Declarations
      2. Using Type Definitions to Simplify Declarations
    5. 18.5 Initializers
      1. Uninitialized Variables
    6. 18.6 Inline Functions (C99)
      1. Inline Definitions
      2. Restrictions on Inline Functions
      3. Using Inline Functions with GCC

    19 PROGRAM DESIGN

    1. 19.1 Modules
      1. Cohesion and Coupling
      2. Types of Modules
    2. 19.2 Information Hiding
      1. A Stack Module
    3. 19.3 Abstract Data Types
      1. Encapsulation
      2. Incomplete Types
    4. 19.4 A Stack Abstract Data Type
      1. Defining the Interface for the Stack ADT
      2. Implementing the Stack ADT Using a Fixed-Length Array
      3. Changing the Item Type in the Stack ADT
      4. Implementing the Stack ADT Using a Dynamic Array
      5. Implementing the Stack ADT Using a Linked List
    5. 19.5 Design Issues for Abstract Data Types
      1. Naming Conventions
      2. Error Handling
      3. Generic ADTs
      4. ADTs in Newer Languages

    20 LOW-LEVEL PROGRAMMING

    1. 20.1 Bitwise Operators
      1. Bitwise Shift Operators
      2. Bitwise Complement, And, Exclusive Or, and Inclusive Or
      3. Using the Bitwise Operators to Access Bits
      4. Using the Bitwise Operators to Access Bit-Fields
      5. Program: XOR Encryption
    2. 20.2 Bit-Fields in Structures
      1. How Bit-Fields Are Stored
    3. 20.3 Other Low-Level Techniques
      1. Defining Machine-Dependent Types
      2. Using Unions to Provide Multiple Views of Data
      3. Using Pointers as Addresses
      4. Program: Viewing Memory Locations
      5. The volatile Type Qualifier

    21 THE STANDARD LIBRARY

    1. 21.1 Using the Library
      1. Restrictions on Names Used in the Library
      2. Functions Hidden by Macros
    2. 21.2 C89 Library Overview
    3. 21.3 C99 Library Changes
    4. 21.4 The stddef.h Header: Common Definitions
    5. 21.5 The stdbool.h Header (C99): Boolean Type and Values

    22 INPUT/OUTPUT

    1. 22.1 Streams
      1. File Pointers
      2. Standard Streams and Redirection
      3. Text Files versus Binary Files
    2. 22.2 File Operations
      1. Opening a File
      2. Modes
      3. Closing a File
      4. Attaching a File to an Open Stream
      5. Obtaining File Names from the Command Line
      6. Program: Checking Whether a File Can Be Opened
      7. Temporary Files
      8. File Buffering 5
      9. Miscellaneous File Operations
    3. 22.3 Formatted I/O
      1. The …printf Functions
      2. …printf Conversion Specifications
      3. C99 Changes to …printf Conversion Specifications
      4. Examples of …printf Conversion Specifications
      5. The …scanf Functions
      6. …scanf Format Strings
      7. …scanf Conversion Specifications
      8. C99 Changes to …scanf Conversion Specifications
      9. scanf Examples
      10. Detecting End-of-File and Error Conditions
    4. 22.4 Character I/O
      1. Output Functions
      2. Input Functions
      3. Program: Copying a File
    5. 22.5 Line I/O
      1. Output Functions
      2. Input Functions
    6. 22.6 Block I/O 571
    7. 22.7 File Positioning
      1. Program: Modifying a File of Part Records
    8. 22.8 String I/O
      1. Output Functions
      2. Input Functions

    23 LIBRARY SUPPORT FOR NUMBERS AND CHARACTER DATA

    1. 23.1 The float.h Header: Characteristics of Floating Types
    2. 23.2 The limits.h Header: Sizes of Integer Types
    3. 23.3 The math.h Header (C89): Mathematics
      1. Errors
      2. Trigonometric Functions
      3. Hyperbolic Functions
      4. Exponential and Logarithmic Functions
      5. Power Functions
      6. Nearest Integer, Absolute Value, and Remainder Functions
    4. 23.4 The math.h Header (C99): Mathematics
      1. IEEE Floating-Point Standard
      2. Types
      3. Macros
      4. Errors
      5. Functions
      6. Classification Macros
      7. Trigonometric Functions
      8. Hyperbolic Functions
      9. Exponential and Logarithmic Functions
      10. Power and Absolute Value Functions
      11. Error and Gamma Functions
      12. Nearest Integer Functions
      13. Remainder Functions
      14. Manipulation Functions
      15. Maximum, Minimum, and Positive Difference Functions
      16. Floating Multiply-Add
      17. Comparison Macros
    5. 23.5 The ctype.h Header: Character Handling
      1. Character-Classification Functions
      2. Program: Testing the Character-Classification Functions
      3. Character Case-Mapping Functions
      4. Program: Testing the Case-Mapping Functions
    6. 23.6 The string.h Header: String Handling
      1. Copying Functions
      2. Concatenation Functions
      3. Comparison Functions
      4. Search Functions
      5. Miscellaneous Functions

    24 ERROR HANDLING

    1. 24.1 The assert.h Header: Diagnostics
    2. 24.2 The errno.h Header: Errors
      1. The perror and strerror Functions
    3. 24.3 The signal.h Header: Signal Handling
      1. Signal Macros
      2. The signal Function
      3. Predefined Signal Handlers
      4. The raise Function
      5. Program: Testing Signals
    4. 24.4 The setjmp.h Header: Nonlocal Jumps
      1. Program: Testing setjmp/longjmp

    25 INTERNATIONAL FEATURES

    1. 25.1 The locale.h Header: Localization
      1. Categories
      2. The setlocale Function
      3. The localeconv Function
    2. 25.2 Multibyte Characters and Wide Characters
      1. Multibyte Characters
      2. Wide Characters
      3. Unicode and the Universal Character Set
      4. Encodings of Unicode
      5. Multibyte/Wide-Character Conversion Functions
      6. Multibyte/Wide-String Conversion Functions
    3. 25.3 Digraphs and Trigraphs
      1. Trigraphs
      2. Digraphs
      3. The iso646.h Header: Alternative Spellings
    4. 25.4 Universal Character Names (C99)
    5. 25.5 The wchar.h Header (C99): Extended Multibyte and Wide-Character Utilities
      1. Stream Orientation
      2. Formatted Wide-Character Input/Output Functions
      3. Wide-Character Input/Output Functions
      4. General Wide-String Utilities
      5. Wide-Character Time-Conversion Functions
      6. Extended Multibyte/Wide-Character Conversion Utilities
    6. 25.6 The wctype.h Header (C99): Wide-Character Classification and Mapping Utilities
      1. Wide-Character Classification Functions
      2. Extensible Wide-Character Classification Functions
      3. Wide-Character Case-Mapping Functions
      4. Extensible Wide-Character Case-Mapping Functions

    26 MISCELLANEOUS LIBRARY FUNCTIONS

    1. 26.1 The stdarg.h Header: Variable Arguments
      1. Calling a Function with a Variable Argument List
      2. The v…printf Functions
      3. The v…scanf Functions
    2. 26.2 The stdlib.h Header: General Utilities
      1. Numeric Conversion Functions
      2. Program: Testing the Numeric Conversion Functions
      3. Pseudo-Random Sequence Generation Functions
      4. Program: Testing the Pseudo-Random Sequence Generation Functions
      5. Communication with the Environment
      6. Searching and Sorting Utilities
      7. Program: Determining Air Mileage
      8. Integer Arithmetic Functions
    3. 26.3 The time.h Header: Date and Time
      1. Time Manipulation Functions
      2. Time Conversion Functions
      3. Program: Displaying the Date and Time

    27 ADDITIONAL C99 SUPPORT FOR MATHEMATICS

    1. 27.1 The stdint.h Header (C99): Integer Types
      1. stdint.h Types
      2. Limits of Specified-Width Integer Types
      3. Limits of Other Integer Types
      4. Macros for Integer Constants
    2. 27.2 The inttypes.h Header (C99): Format Conversion of Integer Types
      1. Macros for Format Specifiers
      2. Functions for Greatest-Width Integer Types
    3. 27.3 Complex Numbers (C99)
      1. Definition of Complex Numbers
      2. Complex Arithmetic
      3. Complex Types in C99
      4. Operations on Complex Numbers
      5. Conversion Rules for Complex Types
    4. 27.4 The complex.h Header (C99): Complex Arithmetic
      1. complex.h Macros
      2. The CX_LIMITED_RANGE Pragma
      3. complex.h Functions
      4. Trigonometric Functions
      5. Hyperbolic Functions
      6. Exponential and Logarithmic Functions
      7. Power and Absolute-Value Functions
      8. Manipulation Functions
      9. Program: Finding the Roots of a Quadratic Equation
    5. 27.5 The tgmath.h Header (C99): Type-Generic Math
      1. Type-Generic Macros
      2. Invoking a Type-Generic Macro
    6. 27.6 The fenv.h Header (C99): Floating-Point Environment
      1. Floating-Point Status Flags and Control Modes
      2. fenv.h Macros
      3. The FENV_ACCESS Pragma
      4. Floating-Point Exception Functions
      5. Rounding Functions
      6. Environment Functions

    Appendix A C Operators

    Appendix B C99 versus C89

    Appendix C C89 versus K&R C

    Appendix D Standard Library Functions

    Appendix E ASCII Character Set

    Bibliography

    Index