Synopses & Reviews
Ever wished you could learn C from a book? Head First C provides a complete learning experience for C and structured imperative programming. With a unique method that goes beyond syntax and how-to manuals, this guide not only teaches you the language, it helps you understand how to be a great programmer. You'll learn key areas such as language basics, pointers and pointer arithmetic, and dynamic memory management. Advanced topics include multi-threading and network programming—topics typically covered on a college-level course.
This book also features labs: in-depth projects intended to stretch your abilities, test your new skills, and build confidence. Head First C mimics the style of college-level C courses, making it ideal as an accessible textbook for students.
We think your time is too valuable to waste struggling with new concepts. Using the latest research in cognitive science and learning theory to craft a multi-sensory learning experience, Head First C uses a visually rich format designed for the way your brain works, not a text-heavy approach that puts you to sleep.
About the Author
David Griffiths began programming at age 12, after being inspired by a documentary on the work of Seymour Papert. At age 15 he wrote an implementation of Papert's computer language LOGO. After studying Pure Mathematics at University, he began writing code for computers and magazine articles for humans and he is currently an agile coach with Exoftware in the UK, helping people to create simpler, more valuable software. He spends his free time traveling and time with his lovely wife, Dawn.
Dawn Griffiths started life as a mathematician at a top UK university. She was awarded a First-Class Honours degree in Mathematics, and was offered a university scholarship to undertake a PhD studying particularly rare breeds of differential equations. She moved away from academia when she realized that people would stop talking to her at parties, and went on to pursue a career in software development instead. She currently combines IT consultancy with writing and mathematics.
When Dawn's not working on Head First books, you'll find her honing her Tai Chi skills, making bobbin lace or cooking nice meals. She hasn't yet mastered the art of doing all three at the same time.
She also enjoys traveling, and spending time with her lovely husband, David.
Table of Contents
; Advance Praise for Head First C; Praise for other Head First books; Authors of Head First C; How to use this Book: Intro; Who is this book for?; We know what you're thinking; We know what your brain is thinking; Metacognition: thinking about thinking; Here's what WE did; Here's what YOU can do to bend your brain into submission; Read me; The technical review team; Acknowledgments; Safari® Books Online; Chapter 1: Getting Started with C: Diving in; 1.1 C is a language for small, fast programs; 1.2 But what does a complete C program look like?; 1.3 But how do you run the program?; 1.4 Two types of command; 1.5 Here's the code so far; 1.6 Card counting? In C?; 1.7 There's more to booleans than equals...; 1.8 What's the code like now?; 1.9 Pulling the ol' switcheroo; 1.10 Sometimes once is not enough...; 1.11 Loops often follow the same structure...; 1.12 You use break to break out...; 1.13 Your C Toolbox; Chapter 2: Memory and Pointers: What are you pointing at?; 2.1 C code includes pointers; 2.2 Digging into memory; 2.3 Set sail with pointers; 2.4 Set sail sou'east, Cap'n; 2.5 Try passing a pointer to the variable; 2.6 Using memory pointers; 2.7 How do you pass a string to a function?; 2.8 Array variables are like pointers...; 2.9 What the computer thinks when it runs your code; 2.10 But array variables aren't quite pointers; 2.11 Why arrays really start at 0; 2.12 Why pointers have types; 2.13 Using pointers for data entry; 2.14 Be careful with scanf(); 2.15 fgets() is an alternative to scanf(); 2.16 Anyone for three-card monte?; 2.17 Oops...there's a memory problem...; 2.18 String literals can never be updated; 2.19 If you're going to change a string, make a copy; 2.20 Memory memorizer; 2.21 Your C Toolbox; Chapter 2.5: Strings: String theory; 3.1 Desperately seeking Susan Frank; 3.2 Create an array of arrays; 3.3 Find strings containing the search text; 3.4 Using the strstr() function; 3.5 It's time for a code review; 3.6 Array of arrays vs. array of pointers; 3.7 Your C Toolbox; Chapter 3: Creating Small Tools: Do one thing and do it well; 4.1 Small tools can solve big problems; 4.2 Here's how the program should work; 4.3 But you're not using files...; 4.4 You can use redirection; 4.5 You can redirect the Standard Input with <...; 4.6="" ...and="" redirect="" the="" standard="" output="" with="">; 4.7 But there's a problem with some of the data...; 4.8 Introducing the Standard Error; 4.9 By default, the Standard Error is sent to the display; 4.10 fprintf() prints to a data stream; 4.11 Let's update the code to use fprintf(); 4.12 Small tools are flexible; 4.13 Don't change the geo2json tool; 4.14 A different task needs a different tool; 4.15 Connect your input and output with a pipe; 4.16 The bermuda tool; 4.17 But what if you want to output to more than one file?; 4.18 Roll your own data streams; 4.19 There's more to main(); 4.20 Overheard at the Head First Pizzeria; 4.21 Let the library do the work for you; 4.22 Your C Toolbox; Chapter 4: Using Multiple Source Files: Break it down, build it up; 5.1 Don't put something big into something small; 5.2 Use casting to put floats into whole numbers; 5.3 Oh no...it's the out-of-work actors...; 5.4 Let's see what's happened to the code; 5.5 Compilers don't like surprises; 5.6 Split the declaration from the definition; 5.7 Creating your first header file; 5.8 If you have common features...; 5.9 You can split the code into separate files; 5.10 Compilation behind the scenes; 5.11 The shared code needs its own header file; 5.12 It's not rocket science...or is it?; 5.13 Don't recompile every file; 5.14 First, compile the source into object files; 5.15 It's hard to keep track of the files; 5.16 Automate your builds with the make tool; 5.17 How make works; 5.18 Tell make about your code with a makefile; 5.19 Your C Toolbox; 5.20 C Lab 1: Arduino; Chapter 5: Structs, Unions, and Bitfields: Roll your own structures; 6.1 Sometimes you need to hand around a lot of data; 6.2 Cubicle conversation; 6.3 Create your own structured data types with a struct; 6.4 Just give them the fish; 6.5 Read a struct's fields with the "." operator; 6.6 Can you put one struct inside another?; 6.7 How do you update a struct?; 6.8 The code is cloning the turtle; 6.9 You need a pointer to the struct; 6.10 (*t).age vs. *t.age; 6.11 Sometimes the same type of thing needs different types of data; 6.12 A union lets you reuse memory space; 6.13 How do you use a union?; 6.14 An enum variable stores a symbol; 6.15 Sometimes you want control at the bit level; 6.16 Bitfields store a custom number of bits; 6.17 Your C Toolbox; Chapter 6: Data Structures and Dynamic Memory: Building bridges; 7.1 Do you need flexible storage?; 7.2 Linked lists are like chains of data; 7.3 Linked lists allow inserts; 7.4 Create a recursive structure; 7.5 Create islands in C...; 7.6 Inserting values into the list; 7.7 Use the heap for dynamic storage; 7.8 Give the memory back when you're done; 7.9 Ask for memory with malloc()...; 7.10 Oh, no! It's the out-of-work actors...; 7.11 Let's fix the code using the strdup() function; 7.12 Free the memory when you're done; 7.13 Exhibit A: the source code; 7.14 An overview of the SPIES system; 7.15 Software forensics: using valgrind; 7.16 Use valgrind repeatedly to gather more evidence; 7.17 Look at the evidence; 7.18 The fix on trial; 7.19 Your C Toolbox; Chapter 7: Advanced Functions: Turn your functions up to 11; 8.1 Looking for Mr. Right...; 8.2 Pass code to a function; 8.3 You need to tell find() the name of a function; 8.4 Every function name is a pointer to the function...; 8.5 ...but there's no function data type; 8.6 How to create function pointers; 8.7 Get it sorted with the C Standard Library; 8.8 Use function pointers to set the order; 8.9 Automating the Dear John letters; 8.10 Create an array of function pointers; 8.11 Make your functions streeeeeetchy; 8.12 Your C Toolbox; Chapter 8: Static and Dynamic Libraries: Hot-swappable code; 9.1 Code you can take to the bank; 9.2 Angle brackets are for standard headers; 9.3 But what if you want to share code?; 9.4 Sharing .h header files; 9.5 Share .o object files by using the full pathname; 9.6 An archive contains .o files; 9.7 Create an archive with the ar command...; 9.8 Finally, compile your other programs; 9.9 The Head First Gym is going global; 9.10 Calculating calories; 9.11 But things are a bit more complex...; 9.12 Programs are made out of lots of pieces...; 9.13 Dynamic linking happens at runtime; 9.14 Can you link .a at runtime?; 9.15 First, create an object file; 9.16 What you call your dynamic library depends on your platform; 9.17 Your C Toolbox; 9.18 C Lab 2: OpenCV; Chapter 9: Processes and System Calls: Breaking boundaries; 10.1 System calls are your hotline to the OS; 10.2 Then someone busted into the system...; 10.3 Security's not the only problem; 10.4 The exec() functions give you more control; 10.5 There are many exec() functions; 10.6 The array functions: execv(), execvp(), execve(); 10.7 Passing environment variables; 10.8 Most system calls go wrong in the same way; 10.9 Read the news with RSS; 10.10 exec() is the end of the line for your program; 10.11 Running a child process with fork() + exec(); 10.12 Your C Toolbox; Chapter 10: Interprocess Communication: It's good to talk; 11.1 Redirecting input and output; 11.2 A look inside a typical process; 11.3 Redirection just replaces data streams; 11.4 fileno() tells you the descriptor; 11.5 Sometimes you need to wait...; 11.6 Stay in touch with your child; 11.7 Connect your processes with pipes; 11.8 Case study: opening stories in a browser; 11.9 In the child; 11.10 In the parent; 11.11 Opening a web page in a browser; 11.12 The death of a process; 11.13 Catching signals and running your own code; 11.14 sigactions are registered with sigaction(); 11.15 Rewriting the code to use a signal handler; 11.16 Use kill to send signals; 11.17 Sending your code a wake-up call; 11.18 Your C Toolbox; Chapter 11: Sockets and Networking: There's no place like 127.0.0.1; 12.1 The Internet knock-knock server; 12.2 Knock-knock server overview; 12.3 BLAB: how servers talk to the Internet; 12.4 A socket's not your typical data stream; 12.5 Sometimes the server doesn't start properly; 12.6 Why your mom always told you to check for errors; 12.7 Reading from the client; 12.8 The server can only talk to one person at a time; 12.9 You can fork() a process for each client; 12.10 Writing a web client; 12.11 Clients are in charge; 12.12 Create a socket for an IP address; 12.13 getaddrinfo() gets addresses for domains; 12.14 Your C Toolbox; Chapter 12: Threads: It's a parallel world; 13.1 Tasks are sequential...or not...; 13.2 ...and processes are not always the answer; 13.3 Simple processes do one thing at a time; 13.4 Employ extra staff: use threads; 13.5 How do you create threads?; 13.6 Create threads with pthread_create; 13.7 The code is not thread-safe; 13.8 You need to add traffic signals; 13.9 Use a mutex as a traffic signal; 13.10 Your C Toolbox; 13.11 C Lab 3: Blasteroids; Leftovers: The top ten things (we didn't cover); #1. Operators; #2. Preprocessor directives; #3. The static keyword; #4. How big stuff is; #5. Automated testing; #6. More on gcc; #7. More on make; #8. Development tools; #9. Creating GUIs; #10. Reference material; C Topics: Revision roundup; Basics; Pointers and memory; Strings; Data streams; Data types; Multiple files; Structs; Unions and bitfields; Data structures; Dynamic memory; Advanced functions; Static and dynamic libraries; Processes and communication; Sockets and networking; Threads;