Books & Videos

Table of Contents

  1. Chapter 1 Getting Started with C: Diving in

    1. C is a language for small, fast programs

    2. But what does a complete C program look like?

    3. But how do you run the program?

    4. Two types of command

    5. Here’s the code so far

    6. Card counting? In C?

    7. There’s more to booleans than equals...

    8. What’s the code like now?

    9. Pulling the ol’ switcheroo

    10. Sometimes once is not enough...

    11. Loops often follow the same structure...

    12. You use break to break out...

    13. Your C Toolbox

  2. Chapter 2 Memory and Pointers: What are you pointing at?

    1. C code includes pointers

    2. Digging into memory

    3. Set sail with pointers

    4. Set sail sou’east, Cap’n

    5. Try passing a pointer to the variable

    6. Using memory pointers

    7. How do you pass a string to a function?

    8. Array variables are like pointers...

    9. What the computer thinks when it runs your code

    10. But array variables aren’t quite pointers

    11. Why arrays really start at 0

    12. Why pointers have types

    13. Using pointers for data entry

    14. Be careful with scanf()

    15. fgets() is an alternative to scanf()

    16. Anyone for three-card monte?

    17. Oops...there’s a memory problem...

    18. String literals can never be updated

    19. If you’re going to change a string, make a copy

    20. Memory memorizer

    21. Your C Toolbox

  3. Chapter 2.5 Strings: String theory

    1. Desperately seeking Susan Frank

    2. Create an array of arrays

    3. Find strings containing the search text

    4. Using the strstr() function

    5. It’s time for a code review

    6. Array of arrays vs. array of pointers

    7. Your C Toolbox

  4. Chapter 3 Creating Small Tools: Do one thing and do it well

    1. Small tools can solve big problems

    2. Here’s how the program should work

    3. But you’re not using files...

    4. You can use redirection

    5. You can redirect the Standard Input with <...

    6. ...and redirect the Standard Output with >

    7. But there’s a problem with some of the data...

    8. Introducing the Standard Error

    9. By default, the Standard Error is sent to the display

    10. fprintf() prints to a data stream

    11. Let’s update the code to use fprintf()

    12. Small tools are flexible

    13. Don’t change the geo2json tool

    14. A different task needs a different tool

    15. Connect your input and output with a pipe

    16. The bermuda tool

    17. But what if you want to output to more than one file?

    18. Roll your own data streams

    19. There’s more to main()

    20. Overheard at the Head First Pizzeria

    21. Let the library do the work for you

    22. Your C Toolbox

  5. Chapter 4 Using Multiple Source Files: Break it down, build it up

    1. Don’t put something big into something small

    2. Use casting to put floats into whole numbers

    3. Oh’s the out-of-work actors...

    4. Let’s see what’s happened to the code

    5. Compilers don’t like surprises

    6. Split the declaration from the definition

    7. Creating your first header file

    8. If you have common features...

    9. You can split the code into separate files

    10. Compilation behind the scenes

    11. The shared code needs its own header file

    12. It’s not rocket science...or is it?

    13. Don’t recompile every file

    14. First, compile the source into object files

    15. It’s hard to keep track of the files

    16. Automate your builds with the make tool

    17. How make works

    18. Tell make about your code with a makefile

    19. Your C Toolbox

    20. C Lab 1: Arduino

  6. Chapter 5 Structs, Unions, and Bitfields: Roll your own structures

    1. Sometimes you need to hand around a lot of data

    2. Cubicle conversation

    3. Create your own structured data types with a struct

    4. Just give them the fish

    5. Read a struct’s fields with the “.” operator

    6. Can you put one struct inside another?

    7. How do you update a struct?

    8. The code is cloning the turtle

    9. You need a pointer to the struct

    10. (*t).age vs. *t.age

    11. Sometimes the same type of thing needs different types of data

    12. A union lets you reuse memory space

    13. How do you use a union?

    14. An enum variable stores a symbol

    15. Sometimes you want control at the bit level

    16. Bitfields store a custom number of bits

    17. Your C Toolbox

  7. Chapter 6 Data Structures and Dynamic Memory: Building bridges

    1. Do you need flexible storage?

    2. Linked lists are like chains of data

    3. Linked lists allow inserts

    4. Create a recursive structure

    5. Create islands in C...

    6. Inserting values into the list

    7. Use the heap for dynamic storage

    8. Give the memory back when you’re done

    9. Ask for memory with malloc()...

    10. Oh, no! It’s the out-of-work actors...

    11. Let’s fix the code using the strdup() function

    12. Free the memory when you’re done

    13. Exhibit A: the source code

    14. An overview of the SPIES system

    15. Software forensics: using valgrind

    16. Use valgrind repeatedly to gather more evidence

    17. Look at the evidence

    18. The fix on trial

    19. Your C Toolbox

  8. Chapter 7 Advanced Functions: Turn your functions up to 11

    1. Looking for Mr. Right...

    2. Pass code to a function

    3. You need to tell find() the name of a function

    4. Every function name is a pointer to the function...

    5. ...but there’s no function data type

    6. How to create function pointers

    7. Get it sorted with the C Standard Library

    8. Use function pointers to set the order

    9. Automating the Dear John letters

    10. Create an array of function pointers

    11. Make your functions streeeeeetchy

    12. Your C Toolbox

  9. Chapter 8 Static and Dynamic Libraries: Hot-swappable code

    1. Code you can take to the bank

    2. Angle brackets are for standard headers

    3. But what if you want to share code?

    4. Sharing .h header files

    5. Share .o object files by using the full pathname

    6. An archive contains .o files

    7. Create an archive with the ar command...

    8. Finally, compile your other programs

    9. The Head First Gym is going global

    10. Calculating calories

    11. But things are a bit more complex...

    12. Programs are made out of lots of pieces...

    13. Dynamic linking happens at runtime

    14. Can you link .a at runtime?

    15. First, create an object file

    16. What you call your dynamic library depends on your platform

    17. Your C Toolbox

    18. C Lab 2: OpenCV

  10. Chapter 9 Processes and System Calls: Breaking boundaries

    1. System calls are your hotline to the OS

    2. Then someone busted into the system...

    3. Security’s not the only problem

    4. The exec() functions give you more control

    5. There are many exec() functions

    6. The array functions: execv(), execvp(), execve()

    7. Passing environment variables

    8. Most system calls go wrong in the same way

    9. Read the news with RSS

    10. exec() is the end of the line for your program

    11. Running a child process with fork() + exec()

    12. Your C Toolbox

  11. Chapter 10 Interprocess Communication: It’s good to talk

    1. Redirecting input and output

    2. A look inside a typical process

    3. Redirection just replaces data streams

    4. fileno() tells you the descriptor

    5. Sometimes you need to wait...

    6. Stay in touch with your child

    7. Connect your processes with pipes

    8. Case study: opening stories in a browser

    9. In the child

    10. In the parent

    11. Opening a web page in a browser

    12. The death of a process

    13. Catching signals and running your own code

    14. sigactions are registered with sigaction()

    15. Rewriting the code to use a signal handler

    16. Use kill to send signals

    17. Sending your code a wake-up call

    18. Your C Toolbox

  12. Chapter 11 Sockets and Networking: There’s no place like

    1. The Internet knock-knock server

    2. Knock-knock server overview

    3. BLAB: how servers talk to the Internet

    4. A socket’s not your typical data stream

    5. Sometimes the server doesn’t start properly

    6. Why your mom always told you to check for errors

    7. Reading from the client

    8. The server can only talk to one person at a time

    9. You can fork() a process for each client

    10. Writing a web client

    11. Clients are in charge

    12. Create a socket for an IP address

    13. getaddrinfo() gets addresses for domains

    14. Your C Toolbox

  13. Chapter 12 Threads: It’s a parallel world

    1. Tasks are sequential...or not...

    2. ...and processes are not always the answer

    3. Simple processes do one thing at a time

    4. Employ extra staff: use threads

    5. How do you create threads?

    6. Create threads with pthread_create

    7. The code is not thread-safe

    8. You need to add traffic signals

    9. Use a mutex as a traffic signal

    10. Your C Toolbox

    11. C Lab 3: Blasteroids

  1. Appendix Leftovers: The top ten things (we didn’t cover)

    1. #1. Operators

    2. #2. Preprocessor directives

    3. #3. The static keyword

    4. #4. How big stuff is

    5. #5. Automated testing

    6. #6. More on gcc

    7. #7. More on make

    8. #8. Development tools

    9. #9. Creating GUIs

    10. #10. Reference material

  2. Appendix C Topics: Revision roundup

    1. Basics

    2. Pointers and memory

    3. Strings

    4. Data streams

    5. Data types

    6. Multiple files

    7. Structs

    8. Unions and bitfields

    9. Data structures

    10. Dynamic memory

    11. Advanced functions

    12. Static and dynamic libraries

    13. Processes and communication

    14. Sockets and networking

    15. Threads