You are previewing Just Enough C/C++ Programming.
O'Reilly logo
Just Enough C/C++ Programming

Book Description

C/C++ programming is often thought of as inaccessible, but these languages form the basis for many other programming languages and paradigms, and as such are vital, necessary skills for any IT professional to learn. Just Enough C/C++ Programming provides an intelligent layperson's guide to programming. The book does not assume you are dimwitted, like so many other beginning programming texts do, but it doesn't assume you are an engineer either. It simply gives you enough C/C++ language knowledge to be able to complete practical, industry-related, programming projects without becoming sidetracked. In short, it teaches you everything you need to know to be a successful programmer, without overloading you on the details. The book begins by explaining the tools you'll need, providing a concise introduction to the world of programming, and explaining the basic structure of a C program. Algorithm design for common programming problems, use of compilers and pre-processors, and the standard ANSI C libraries are all covered in enough detail so that you can pick up and apply the knowledge immediately. Next, the book covers the most relevant differences between C and C++, including C++ Standard Libraries, templates, and STL. The companion web site includes usable sample code for download and key pointers on how the code can be adapted for real-world use. Perfect for any aspiring software developer, Just Enough C/C++ Programming offers both a comfortable read, and practical, applicable, ready-to-use knowledge.

Table of Contents

  1. Copyright
    1. Dedication
  2. Acknowledgments
  3. About the Author
  4. Introduction
    1. What’s On the Companion Web Site
  5. Getting Started
    1. Conventions Used in This Book
    2. How to Use This Book
      1. Study Areas
      2. Reference
    3. Choosing the Right Tools
      1. Editor
      2. Compiler and Linker
      3. Debugger
    4. Inside Your Computer
    5. Using Open Source Resources
    6. Recap
  6. Programming Recap
    1. What Is Programming?
      1. Programming, Testing, and Debugging
    2. Procedural Programming
      1. Program Flow
        1. Decision Making
      2. Data Storage
      3. Parts of a Language
    3. Compiling and Linking
    4. Executable File Format
    5. External Files (Header Files)
    6. Recap
  7. C Program Structure
    1. The Entry and Exit Points
    2. Declaring Variables
    3. Operators, Comparison, and Precedence
      1. Operators
      2. Comparing Values
      3. Precedence
    4. Containing Code Blocks
      1. Variable Scoping
    5. Comments
    6. Defining Functions
      1. Code Sample 3.2: Simple Skeleton Application
      2. Building the Application
      3. If the Application Fails to Build
    7. Recap
  8. Data Types and Variables
    1. Basic Types
      1. Sizes and Ranges
      2. Complex Data Types
    2. Casting
    3. Arrays
    4. Enumerated Types
    5. Data Types and Variables
    6. Recap
  9. Console I/O
    1. Formatted Output
      1. Using printf
      2. Using sprintf
    2. Formatted Input
      1. Using scanf
      2. Using sscanf
        1. Code Sample 5.3: The PercentageCalculator Program
    3. Non-Formatted I/O
      1. Character Processing
      2. String Processing
    4. Recap
  10. Decision Making
    1. The Basic if Statement
      1. Compound Condition Statements
      2. The else Keyword
      3. Using else if
      4. Nesting
    2. The switch Statement
    3. Recap
  11. Loops
    1. The for Loop
    2. The while Loop
      1. More do and while
    3. Using break and continue
    4. Nesting Loops
    5. Scoping Revisited
    6. Recap
  12. Standard Libraries
    1. Standard I/O: stdio.h
      1. Code Sample 8.1: File Open or Create
      2. Code Sample 8.2: File Size
      3. Code Sample 8.3: Write String to File
    2. String Handling: string.h
    3. Math Functions: math.h
      1. Code Sample 8.4: Degrees to Radians to Degrees
    4. Memory Handling: malloc.h
    5. The Standard Library: stdlib.h
      1. Code Sample 8.5: Integer Comparison Function
    6. The Time Library: time.h
    7. Recap
  13. Command-Line Processing
    1. The argv and argc Variables
    2. Processing the Command Line
      1. Code Sample 9.1: Searching Command-Line Supplied Parameters
    3. Conditional Execution
      1. Reporting Parameter Errors
      2. Adding a Debug Flag
      3. Displaying Help
    4. Recap
  14. User-Defined Functions
    1. Declaring Functions
      1. Prototyping
      2. Libraries and Linking
    2. Function Parameter Lists
      1. Passing by Value
      2. Passing by Reference
    3. Recursion
    4. Recap
  15. File I/O
    1. Formatted I/O Revisited
    2. Fully Qualified Pathnames
      1. Using fprintf
      2. Using fscanf
        1. Code Sample 11.2: Reading Multiple Integers from a File
      3. Using fprintf and scanf Together
    3. Unformatted I/O Revisited
      1. Using Single Character I/O
      2. Using Line-Based Multicharacter I/O
    4. Binary Input and Output
      1. Using fread and fwrite
    5. Directory Management
      1. Creating and Deleting Directories
      2. Renaming and Deleting Files
      3. Searching for Files and Directories
    6. Recap
  16. Complex Data Types
    1. The struct and union Keywords
      1. The struct Keyword
      2. The union Keyword
    2. Accessing Data
      1. Code Sample 12.2: Manipulating Time and Date structs
      2. Accessing Data in unions
    3. File Processing with Complex Data Types
      1. Code Sample 12.3: File I/O with structs as Memory Objects
      2. Code Sample 12.4: Reading structs into a Dynamic Memory Block
    4. File Processing with unions
      1. Code Sample 12.6: Writing a union to File
      2. Code Sample 12.7: Reading Individual Members of a union from a File
    5. Recap
  17. Pointers
    1. Strings Revisited
    2. Pointers and References
      1. Dereferencing
    3. Pointers and Memory
      1. Example: A Linked List of Command-Line Arguments
      2. Creating the Linked List
      3. Destroying the List
    4. Recap
  18. Pre-Processor Directives
    1. The Pre-Processor Concept
    2. The #include Directive
    3. The #define Directive
      1. Avoiding Multiple Includes
      2. Using Pre-Processor Directives for Debugging
    4. C-Style Macros
    5. Conditional Compilation with #if
    6. Recap
  19. Program Design in C and C++
    1. Object-Oriented Design
    2. The Problem Domain
      1. Encapsulation and Messages
      2. A Simple Example: Text Editor
    3. Object-Oriented Programming
      1. Classes
    4. Prototyping Revisited
    5. C++ Header Files
    6. C++ Source Files
    7. Recap
  20. C++ in Practice
    1. Differences in Code Organization
      1. Declarations
      2. Scope
      3. New Operators and Features
    2. Defining Classes
      1. Constructors
      2. Destructors
      3. Example: A Linked List of Command-Line Arguments (Revisited)
      4. Inheritance and Polymorphism
      5. Overloading
    3. Exception Handling
    4. Recap
  21. C++ Standard Libraries
    1. Introduction to the C++ Libraries
      1. The C Language Library
      2. Using Namespaces
    2. IO Libraries
      1. Stream Classes
      2. Manipulators
      3. Base Class Functionality
      4. File Access with iostream
    3. String Libraries
    4. Recap
  22. Templates and the STL
    1. Templates
      1. Template Functions
      2. Template Classes
    2. The STL
      1. STL Containers
      2. STL Algorithms
      3. STL Headers
      4. Container Classes
        1. Vector
        2. Deque
        3. List
        4. Stack
        5. Queue
      5. Algorithms
      6. Iterators
      7. User-Defined Classes and the using Keyword
    3. Recap
  23. Where Next?
    1. Programming for Reuse
      1. Reuse in Design
      2. Reuse in C Programming
    2. Reuse in C++ Programming
    3. Open Source and Glue Code
  24. Web References
    1. Compilers
      1. Linux
      2. TheFreeCountry.com
      3. Microsoft
      4. Borland
      5. Apple Macintosh
    2. Source Code
      1. The Code Project
      2. SourceForge
    3. C and C++ Programming
      1. C/C++ at About.com
      2. The C++ Resources Network
      3. Cprogramming.com
      4. The C Programming Language Wikipedia Entry
      5. Programming User Groups