Skip to main content
main-content
Top

About this book

Learn practical C techniques, including often-needed algorithms within reusable functions. In this book, you'll have the following code and advice at your fingertips: layout and pre-processors; control structures, iterations, and selections; pointers and structures; databases; reusability; lists, arrays, FIFO and stacks; searching and sorting; recursion; binary trees; integration; string utilities in/outside of C; web serving using Mongoose; game application code to build a MathSearch puzzle; and embedded software.
Besides providing you with modules that you can immediately put to use, Practical C also teaches you how to leverage the C language in a way that beginner books cannot achieve.

What You Will Learn:
Avoid pitfalls that can cause intractable problems
Handle lists and arrays
Perform searches and sorts
Binary trees
Take advantage of recursion
Handle exceptions
Access databases
Calculate integrals using numerical computation with practical applications
Deal with strings in a convenient, error-free way
Build a MathSearch game application, similar to WordSearch puzzle games
Deal with issues specific to embedded applications

Who This Book Is For

Programmers who have a general knowledge of C.

Table of Contents

Chapter 1. Introduction

Abstract
Because this is a book of recipes, you will not find a description of C, although to ensure that we are all on the same page (pun entirely intended!), I sometimes include brief explanations of individual features of the language.
Giulio Zambon

Chapter 2. Tricky Bits

Abstract
C includes features that are often misunderstood and can therefore cause problems and unexpected results. This chapter talks about those tricky bits (pun intended!).
Giulio Zambon

Chapter 3. Iteration, Recursion, and Binary Trees

Abstract
Iteration and recursion are strategies to solve complex problems by repeatedly performing simpler operations. But while iteration involves repeating the same operation in a loop, recursion means partially solving increasingly simpler cases of the problem until you reach base cases for which you already have a solution.
Giulio Zambon

Chapter 4. Lists, Stacks, and Queues

Abstract
We are all familiar with lists: in very generic terms, a list is an ordered collection of items, and in the context of programming languages, the items are simple or structured data types. Individual lists can contain items of mixed types, but in this chapter you will only see homogeneous lists, in which all items are values of a single data type.
Giulio Zambon

Chapter 5. Exception Handling

Abstract
When talking about why computer programs fail, many people distinguish between user errors and developer/programmer errors (i.e., bugs). But such a distinction is, in my opinion, ill defined. For example, suppose that a program requires the users to type a date into an input field, somebody enters a negative number as day of the month, and the program crashes. It is true that the user made a mistake, but the program should have been able to recognize and cope with such the input error. Where do you draw the line?
Giulio Zambon

Chapter 6. String Utilities

Abstract
In C strings are null-terminated arrays of characters. You can manipulated them with a series of functions declared in the standard header file string.h, but there are two drawbacks.
Giulio Zambon

Chapter 7. Dynamic Arrays

Abstract
The size of arrays in C is set at compile time. In the previous chapter, you learned a way of defining dynamically allocated C strings, which are arrays of characters. In this chapter, you will see how you can define at runtime arrays of any type. If you haven’t read Chapter 6, I suggest that you quickly go through it, so that you can use it as a reference for this chapter.
Giulio Zambon

Chapter 8. Searching

Abstract
Searches work by comparing primitive or structured data types. Therefore, it makes sense to begin this chapter with a section about comparisons.
Giulio Zambon

Chapter 9. Sorting

Abstract
In the previous chapter, you read about ordered arrays and binary trees. In particular, you have learned how to work with ordered arrays of pointers to insert, delete, and find individual items.
Giulio Zambon

Chapter 10. Numerical Integration

Abstract
Numerical integration is the part of numerical analysis that studies how to calculate values of integrals. It is concerned with calculating definite integrals, like the example shown in Figure 10-1, rather than analytically resolve indefinite integral like that shown in Figure 10-2.
Giulio Zambon

Chapter 11. Embedded Software

Abstract
The first things that come to mind for many people, when talking about software, are applications. That is, programs with which we interact directly, like web browsers and games. We issue commands by typing on a keyboard, clicking mouse buttons, or touching a screen, and the applications respond by performing tasks, hopefully those we intend them to do.
Giulio Zambon

Chapter 12. Databases

Abstract
A database consists of organized data—that is, the data itself and a schema that provides data structures. Nowadays, most databases are organized in tables, and you can define the table characteristics independently of the actual data you’re going to store into it.
Giulio Zambon

Chapter 13. Web Server Using Mongoose

Abstract
In this chapter you will learn how to embed a web server in C programs. That is, any of your applications written in C will be able to serve web pages. The next two sections will explain some concepts and facts concerning the Web that you need to have completely clear in order to understand the rest of the chapter without problems. If you are familiar with how the Web works, feel free to skip them.
Giulio Zambon

Chapter 14. Game Application: MathSearch

Abstract
In this chapter, you will learn how to generate MathSearch numeric puzzles like the one shown in Figure 14-1.
Giulio Zambon
Additional information