Programming in C

(Barry) #1
        - 1 Introduction Preface xvii
- 2 Some Fundamentals
- 3 Compiling and Running Your First Program
- Expressions 4 Va r iables, Data Types, and Arithmetic
- 5 Program Looping
- 6 Making Decisions
- 7 Working with Arrays
- 8 Working with Functions
- 9 Working with Structures


  • 10 Character Strings

  • 11 Pointers

  • 12 Operations on Bits

  • 13 The Preprocessor

  • 14 More on Data Types

  • 15 Working with Larger Programs

  • 16 Input and Output Operations in C

  • 17 Miscellaneous and Advanced Features

  • 18 Debugging Programs

  • 19 Object-Oriented Programming

    • A C Language Summary

    • B The Standard C Library

    • C Compiling Programs with gcc

    • D Common Programming Mistakes

      • E Resources

        • Index







  • 1 Introduction Table of Contents

  • 2 Some Fundamentals

    • Programming

    • Higher-Level Languages

    • Operating Systems

    • Compiling Programs

    • Integrated Development Environments

    • Language Interpreters

    • Program 3 Compiling and Running Your First

    • Compiling Your Program

    • Running Your Program

    • Understanding Your First Program

    • Displaying the Values of Variables

    • Comments

    • Exercises

    • Expressions 4Variables, Data Types, and Arithmetic

    • Working with Variables

    • Understanding Data Types and Constants

      • The Basic Integer Type int

      • The Floating Number Type float

      • The Extended Precision Type double

      • The Single Character Type char

      • The Boolean Data Type _Bool

      • unsigned,and signed Type Specifiers:long,long long,short,



    • Working with Arithmetic Expressions

      • Operator Integer Arithmetic and the Unary Minus

      • The Modulus Operator

      • Integer and Floating-Point Conversions



    • Assignment Operators Combining Operations with Assignment:The

    • Types _Complexand _Imaginary

    • Exercises



  • 5Program Looping

    • The forStatement

      • Relational Operators

      • Aligning Output

      • Program Input

      • Nested forLoops

      • forLoop Variants



    • The whileStatement

    • The doStatement

      • The breakStatement

      • The continueStatement



    • Exercises



  • 6 Making Decisions

    • The ifStatement

      • The if-elseConstruct

      • Compound Relational Tests

      • Nested ifStatements

      • The else ifConstruct



    • The switchStatement

    • Boolean Variables

    • The Conditional Operator

    • Exercises



  • 7Working with Arrays

    • Defining an Array

      • Using Array Elements as Counters

      • Generating Fibonacci Numbers

      • Using an Array to Generate Prime Numbers



    • Initializing Arrays

    • Character Arrays Contents ix

      • Base Conversion Using Arrays

      • The constQualifier



    • Multidimensional Arrays

    • Va r iable-Length Arrays

    • Exercises



  • 8Working with Functions

    • Defining a Function

    • Arguments and Local Variables

      • Function Prototype Declaration

      • Automatic Local Variables



    • Returning Function Results

    • Functions Calling Functions Calling...

      • Declaring Return Types and Argument Types

      • Checking Function Arguments



    • Top-Down Programming

    • Functions and Arrays

      • Assignment Operators

      • Sorting Arrays

      • Multidimensional Arrays



    • Global Variables

    • Automatic and Static Variables

    • Recursive Functions

    • Exercises



  • 9Working with Structures

    • A Structure for Storing the Date

      • Using Structures in Expressions



    • Functions and Structures

      • A Structure for Storing the Time



    • Initializing Structures

      • Compound Literals



    • Arrays of Structures

    • Structures Containing Structures

    • Structures Containing Arrays x Contents

    • Structure Variants

    • Exercises



  • 10 Character Strings

    • Arrays of Characters

    • Va r iable-Length Character Strings

      • Strings Initializing and Displaying Character

      • Testing Two Character Strings for Equality

      • Inputting Character Strings

      • Single-Character Input

      • The Null String



    • Escape Characters

    • More on Constant Strings

    • Character Strings, Structures, and Arrays

      • A Better Search Method



    • Character Operations

    • Exercises



  • 11 Pointers

    • Defining a Pointer Variable

    • Using Pointers in Expressions

    • Working with Pointers and Structures

      • Structures Containing Pointers

      • Linked Lists



    • The Keyword constand Pointers

    • Pointers and Functions

    • Pointers and Arrays

      • Optimization A Slight Digression About Program

      • Is It an Array or Is It a Pointer?

      • Pointers to Character Strings

      • Constant Character Strings and Pointers

      • Revisited The Increment and Decrement Operators



    • Operations on Pointers

    • Pointers to Functions Contents xi

    • Pointers and Memory Addresses

    • Exercises



  • 12 Operations on Bits

    • Bit Operators

      • The Bitwise AND Operator

      • The Bitwise Inclusive-OR Operator

      • The Bitwise Exclusive-OR Operator

      • The Ones Complement Operator

      • The Left Shift Operator

      • The Right Shift Operator

      • A Shift Function

      • Rotating Bits



    • Bit Fields

    • Exercises



  • 13 The Preprocessor

    • The #defineStatement

      • Program Extendability

      • Program Portability

      • More Advanced Types of Definitions

      • The #Operator

      • The ##Operator



    • The #includeStatement

      • System Include Files



    • Conditional Compilation

      • Statements The #ifdef,#endif,#else,and #ifndef

      • Statements The #ifand #elifPreprocessor

      • The #undefStatement



    • Exercises



  • 14 More on Data Types

    • Enumerated Data Types

    • The typedefStatement

    • Data Type Conversions xii Contents

      • Sign Extension

      • Argument Conversion



    • Exercises



  • 15 Working with Larger Programs

    • Dividing Your Program into Multiple Files

      • Command Line Compiling Multiple Source Files from the



    • Communication Between Modules

      • External Variables

      • Functions StaticVe r sus ExternVa r iables and

      • Using Header Files Effectively



    • Programs Other Utilities for Working with Larger

      • The makeUtility

      • The cvsUtility

      • Unix Utilities:ar,grep,sed, and so on





  • 16 Input and Output Operations in C

    • Character I/O:getcharand putchar

    • Formatted I/O:printfand scanf

      • The printfFunction

      • The scanfFunction



    • Input and Output Operations with Files

      • Redirecting I/O to a File

      • End of File



    • Special Functions for Working with Files

      • The fopenFunction

      • The getcand putcFunctions

      • The fcloseFunction

      • The feofFunction

      • The fprintfand fscanfFunctions

      • The fgetsand fputsFunctions

      • stdin,stdout, and stderr

      • The exitFunction

      • Renaming and Removing Files



    • Exercises



  • 17 Miscellaneous and Advanced Features Contents xiii

    • Miscellaneous Language Statements

      • The gotoStatement

      • The nullStatement



    • Working with Unions

    • The Comma Operator

    • Type Qualifiers

      • The registerQualifier

      • The volatileQualifier

      • The restrictQualifier



    • Command-Line Arguments

    • Dynamic Memory Allocation

      • The callocand mallocFunctions

      • The sizeofOperator

      • The freeFunction





  • 18 Debugging Programs

    • Debugging with the Preprocessor

    • Debugging Programs with gdb

      • Working with Variables

      • Source File Display

      • Controlling Program Execution

      • Getting a Stack Trace

      • Structures Calling Functions and Setting Arrays and

      • Getting Help with gdbCommands

      • Odds and Ends





  • 19 Object-Oriented Programming

    • What Is an Object Anyway?

    • Instances and Methods

    • Writing a C Program to Work with Fractions

    • Fractions Defining an Objective-C Class to Work with

    • Defining a C++ Class to Work with Fractions

    • Defining a C# Class to Work with Fractions



  • AC Language Summary xiv Contents

    • 1.0 Digraphs and Identifiers

      • 1.1 Digraph Characters

      • 1.2 Identifiers



    • 2.0 Comments

    • 3.0 Constants

      • 3.1 Integer Constants

      • 3.2 Floating-Point Constants

      • 3.3 Character Constants

      • 3.4 Character String Constants

      • 3.5 Enumeration Constants



    • 4.0 Data Types and Declarations

      • 4.1 Declarations

      • 4.2 Basic Data Types

      • 4.3 Derived Data Types

      • 4.4 Enumerated Data Types

      • 4.5 The typedefStatement

      • restrict 4.6 Type Modifiers const,volatile,and



    • 5.0 Expressions

      • 5.1 Summary of C Operators

      • 5.2 Constant Expressions

      • 5.3 Arithmetic Operators

      • 5.4 Logical Operators

      • 5.5 Relational Operators

      • 5.6 Bitwise Operators

      • 5.7 Increment and Decrement Operators

      • 5.8 Assignment Operators

      • 5.9 Conditional Operators

      • 5.10 Type Cast Operator

      • 5.11 sizeofOperator

      • 5.12 Comma Operator

      • 5.13 Basic Operations with Arrays

      • 5.14 Basic Operations with Structures

      • 5.15 Basic Operations with Pointers

      • 5.16 Compound Literals

      • 5.17 Conversion of Basic Data Types



    • 6.0 Storage Classes and Scope Contents xv

      • 6.1 Functions

      • 6.2 Variables



    • 7.0 Functions

      • 7.1 Function Definition

      • 7.2 Function Call

      • 7.3 Function Pointers



    • 8.0 Statements

      • 8.1 Compound Statements

      • 8.2 The breakStatement

      • 8.3 The continueStatement

      • 8.4 The doStatement

      • 8.5 The forStatement

      • 8.6 The gotoStatement

      • 8.7 The ifStatement

      • 8.8 The nullStatement

      • 8.9 The returnStatement

      • 8.10 The switchStatement

      • 8.11 The whileStatement



    • 9.0 The Preprocessor

      • 9.1 Trigraph Sequences

      • 9.2 Preprocessor Directives

      • 9.3 Predefined Identifiers





  • B The Standard C Library

    • Standard Header Files


















    • String Functions

    • Memory Functions

    • Character Functions

    • I/O Functions

    • In-Memory Format Conversion Functions

    • String-to-Number Conversion

      • Dynamic Memory Allocation Functions xvi Contents

      • Math Functions

        • Complex Arithmetic



      • General Utility Functions



    • C Compiling Programs with gcc

      • General Command Format

      • Command-Line Options





  • D Common Programming Mistakes

    • EResources

      • Answers to Exercises, Errata, etc.

      • The C Programming Language

        • Books

        • Web Sites

        • Newsgroups



      • Environments C Compilers and Integrated Development

        • gcc

        • MinGW

        • CygWin

        • Visual Studio

        • CodeWarrior

        • Kylix



      • Miscellaneous

        • Object-Oriented Programming

        • The C++ Language

        • The C# Language

        • The Objective-C Language

        • Development Tools



      • Index





Free download pdf