You are previewing C Programming for the Absolute Beginner, Second Edition.
O'Reilly logo
C Programming for the Absolute Beginner, Second Edition

Book Description

If you are new to programming with C and are looking for a solid introduction, this is the book for you. Developed by computer science instructors, books in the for the absolute beginner™ series teach the principles of programming through simple game creation. C is not an easy language to learn, but fortunately the clear explanations, examples, and pictures in this book make learning C easy and fun. Each chapter contains programming challenges, a chapter review, and a complete program that uses chapter-based concepts to construct an easily built application. You will acquire the skills that you need for more practical C programming applications and will learn how these skills can be put to use in real-world scenarios. Additionally, by the time you finish this book, you will be able to apply the programming principles you've learned to the next programming language you tackle.

Table of Contents

  1. Copyright
    1. Dedication
  2. Acknowledgments
  3. About the Author
  4. Introduction
    1. What You’ll Find in This Book
    2. Who This Book Is For
  5. 1. Getting Started with C Programming
    1. Installing and Configuring the Cygwin Environment
    2. main() Function
    3. Comments
    4. Keywords
    5. Program Statements
      1. Escape Sequence \n
      2. Escape Sequence \t
      3. Escape Sequence \r
      4. Escape Sequence \\
      5. Escape Sequence \“
      6. Escape Sequence \’
    6. Directives
    7. gcc Compiler
    8. How to Debug C Programs
      1. Common Error #1: Missing Program Block Identifiers
      2. Common Error #2: Missing Statement Terminators
      3. Common Error #3: Invalid Preprocessor Directives
      4. Common Error #4: Invalid Escape Sequences
      5. Common Error #5: Invalid Comment Blocks
    9. Summary
  6. 2. Primary Data Types
    1. Memory Concepts
    2. Data Types
      1. Integers
      2. Floating-Point Numbers
      3. Characters
    3. Initializing Variables and the Assignment Operator
    4. Printing Variable Contents
    5. Conversion Specifiers
      1. Displaying Integer Data Types with printf()
      2. Displaying Floating-Point Data Types with printf()
      3. Displaying Character Data Types with printf()
    6. Constants
    7. Programming Conventions and Styles
      1. White Space
      2. Variable Naming Conventions
      3. Identifying Data Types with a Prefix
      4. Using Uppercase and Lowercase Letters Appropriately
      5. Give Variables Meaningful Names
    8. scanf()
    9. Arithmetic in C
    10. Operator Precedence
    11. Chapter Program—Profit Wiz
    12. Summary
  7. 3. Conditions
    1. Algorithms for Conditions
      1. Expressions and Conditional Operators
      2. Pseudo Code
      3. Flowcharts
    2. Simple if Structures
    3. Nested if Structures
    4. Introduction to Boolean Algebra
      1. and Operator
      2. or Operator
      3. not Operator
      4. Order of Operations
      5. Building Compound Conditions with Boolean Operators
    5. Compound if Structures and Input Validation
      1. && Operator
      2. || Operator
      3. Checking for Upper- and Lowercase
      4. Checking for a Range of Values
      5. isdigit() Function
    6. The switch Structure
    7. Random Numbers
    8. Chapter Program—Fortune Cookie
    9. Summary
  8. 4. Looping Structures
    1. Pseudo Code for Looping Structures
    2. Flowcharts for Looping Structures
    3. Operators Continued
      1. ++ Operator
      2. -- Operator
      3. +| Operator
      4. -= Operator
    4. The while Loop
    5. The do while Loop
    6. The for Loop
    7. break and continue Statements
    8. System Calls
    9. Chapter Program: Concentration
    10. Summary
  9. 5. Structured Programming
    1. Introduction to Structured Programming
      1. Top-Down Design
      2. Code Reusability
      3. Information Hiding
    2. Function Prototypes
    3. Function Definitions
    4. Function Calls
    5. Variable Scope
      1. Local Scope
      2. Global Scope
    6. Chapter Program—Trivia
    7. Summary
  10. 6. Arrays
    1. Introduction to Arrays
    2. One-Dimensional Arrays
      1. Creating One-Dimensional Arrays
      2. Initializing One-Dimensional Arrays
      3. Searching One-Dimensional Arrays
    3. Two-Dimensional Arrays
      1. Initializing Two-Dimensional Arrays
      2. Searching Two-Dimensional Arrays
    4. Chapter Program—Tic-Tac-Toe
    5. Summary
  11. 7. Pointers
    1. Pointer Fundamentals
      1. Declaring and Initializing Pointer Variables
      2. Printing Pointer Variable Contents
    2. Functions and Pointers
    3. Passing Arrays to Functions
    4. The const Qualifier
    5. Chapter Program—Cryptogram
      1. Introduction to Encryption
      2. Building the Cryptogram Program
    6. Summary
  12. 8. Strings
    1. Introduction to Strings
    2. Reading and Printing Strings
    3. String Arrays
    4. Converting Strings to Numbers
    5. Manipulating Strings
      1. strlen()
      2. tolower() and toupper()
      3. strcpy()
      4. strcat()
    6. Analyzing Strings
      1. strcmp()
      2. strstr()
    7. Chapter Program—Word Find
    8. Summary
  13. 9. Introduction to Data Structures
    1. Structures
      1. struct
      2. typedef
      3. Arrays of Structures
    2. Passing Structures to Functions
      1. Passing Structures by Value
      2. Passing Structures by Reference
      3. Passing Arrays of Structures
    3. Unions
    4. Type Casting
    5. Chapter Program—Card Shuffle
    6. Summary
  14. 10. Dynamic Memory Allocation
    1. Memory Concepts Continued
      1. Stack and Heap
    2. sizeof
    3. malloc()
      1. Managing Strings with malloc()
      2. Freeing Memory
      3. Working with Memory Segments
    4. calloc() and realloc()
    5. Chapter Program—Math Quiz
    6. Summary
  15. 11. File Input and Output
    1. Introduction to Data Files
      1. Bits and Bytes
      2. Fields, Records, and Files
    2. File Streams
      1. Opening and Closing Files
      2. Reading Data
      3. Writing Data
      4. Appending Data
    3. goto and Error Handling
    4. Chapter Program—The Phone Book Program
    5. Summary
  16. 12. The C Preprocessor
    1. Introduction to the C Preprocessor
      1. Symbolic Constants
      2. Creating and Using Macros
    2. Building Larger Programs
      1. Header File
      2. Function Definition File
      3. main() Function File
      4. Pulling It All Together
    3. Chapter Program—The Function Wizard
      1. ch12_calculate.h
      2. ch12_calculate.c
      3. ch12_main.c
    4. Summary
    5. What’s Next?
  17. A. Common UNIX Commands
  18. B. VIM Quick Guide
  19. C. Nano Quick Guide
  20. D. Common ASCII Character Codes
  21. E. Common C Library Functions